Check if class exists somewhere in parent - vanilla JS
<p>I'm really struggling to see how to do this. 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 "the-class" 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="the-class"&gt;
        &lt;div id="the-element"&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>So does this:</p>

<pre><code>&lt;div class="the-class"&gt;
    &lt;div&gt;
        &lt;div id="the-element"&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="the-class"&gt;
    &lt;/div&gt;
    &lt;div id="the-element"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>
