title: Jquery - Find the closest parent having a class name
body: <p>In my application i want to find the closest parent, of a clicked element, having a class name. For that i have the following code with <a href="http://api.jquery.com/closest/" rel="noreferrer">closest</a> method. I know it has the functionality to get the closest element with a selector. But here i given a class name as selector like;</p>
  
  <pre><code>$(".selectable").click(function(){
      var closest  = $(this).closest('.selectable'); 
  });    
  </code></pre>
  
  <p>The problem is if the current element and its parent have the same class <code>.selectable</code>, it returns the current element itself. But actually i want its parent. For example,</p>
  
  <pre><code>&lt;div class="selectable div-1"&gt;
      &lt;div class="selectable div-2"&gt;
          &lt;!--elements here--&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In the above example i clicked on <code>.div-2</code> div, it returns the <code>.div-2</code> itself, not the <code>.div-1</code> div. Please dont ask me to remove <code>.selectable</code> class from the parent, it's for the functionality.. :-)</p>