title: How to take the closest/nearest element of a specific class
body: <p>I am trying to get the closest/nearest class of a specific element.</p>
  
  <p>How can I make it work? I am currently trying to use .closest.</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="test"&gt;.test&lt;/div&gt;    &lt;!-- Not this --&gt;
  &lt;div&gt;
     &lt;div class="test"&gt;.test&lt;/div&gt; &lt;!-- That's the one I need to grab --&gt;
  &lt;/div&gt;
  &lt;div id="test"&gt;&lt;/div&gt;            &lt;!-- This is the reference element --&gt;
  &lt;div class="another"&gt;&lt;/div&gt;
  &lt;div class="another"&gt;&lt;/div&gt;
  &lt;div class="test"&gt;.test&lt;/div&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>var test = $('#test2').closest('.test');
  console.log(test);
  </code></pre>
  
  <p>If closest isn't the right method, how can I actually grab the closest 'test' class?</p>
  
  <p>I tried parentsUntil() as well.</p>
  
  <p>Actually if that can help, in my use case I will ALWAYS need the nearest PARENT element of a specific class, whether that parent element is within another element or not, like in this HTML example.</p>