title: Find the closest ancestor element that has a specific class
body: <p>How can I find an element's ancestor that is closest up the tree that has a particular class, <strong>in pure JavaScript</strong>? For example, in a tree like so:</p>
  
  <pre><code>&lt;div class="far ancestor"&gt;
      &lt;div class="near ancestor"&gt;
          &lt;p&gt;Where am I?&lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Then I want <code>div.near.ancestor</code> if I try this on the <code>p</code> and search for <code>ancestor</code>.</p>