title: Check if class exists somewhere in parent
body: <p>I want to check if a class exsits somewhere in one of the parent elements of an element.</p>
  <p>I don't want to use any library, just vanilla JS.</p>
  <p>In the examples below it should return true if the element in question resides somewhere in the childs of an element with &quot;the-class&quot; as the class name.</p>
  <p>I think it would be something like this with jQuery:</p>
  <pre><code>if( $('#the-element').parents().hasClass('the-class') ) {
      return true;
  }
  </code></pre>
  <p>So this returns true:</p>
  <pre><code>&lt;div&gt;
      &lt;div class=&quot;the-class&quot;&gt;
          &lt;div id=&quot;the-element&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>So does this:</p>
  <pre><code>&lt;div class=&quot;the-class&quot;&gt;
      &lt;div&gt;
          &lt;div id=&quot;the-element&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>...but this returns false:</p>
  <pre><code>&lt;div&gt;
      &lt;div class=&quot;the-class&quot;&gt;
      &lt;/div&gt;
      &lt;div id=&quot;the-element&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>