title: Get closest parent element (excluding current element) using a selector
body: <p>I am trying to get the closest Parent element of an element.</p>
  <p>Looking at <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/closest" rel="noreferrer"><code>.closest()</code></a>, it seems to return the element itself if the selector matches with it:</p>
  <blockquote>
  <p>The closest() method traverses the Element and its parents (heading
  toward the document root) until it finds a node that matches the
  provided selector string. <strong>Will return itself</strong> or the matching ancestor.
  If no such element exists, it returns null.</p>
  </blockquote>
  <p>(emphasis is mine)</p>
  <p>So, what would be the best way to get the closest Parent of an element given a selector?</p>
  <p><strong>Example</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var el = document.getElementById('foo');
  var closestParent = el.closest('div');
  console.log(closestParent);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div&gt;root
    &lt;div&gt;level1
      &lt;div id='foo'&gt;level2&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>As you can see, <code>el.closest('div');</code> returns <code>el</code> itself, not its closest parent matching the selector <code>div</code> (level1), which is what I need.</p>
  <p>I know that in this case I can simply do <code>closestParent.parentElement</code>, but this is just an example, and I am trying to figure out if it possible to avoid <code>.closest()</code> to return the element itself.</p>