Q:

jquery closest returns undefined if apply on class attribute

While running following jquery code i am constantly getting 'undefined' in alert box. If i replace class="back" with id="back" and reflect same in jquery code , it works fine. But i am in situation such that closest need to be of class not an id. How to resolve this?
HTML : 
<div id="up">
  <div id="boom">
  <div class="back">  </div>
  </div>
</div>

JQUERY : 
$(document).ready(function(){
  alert($(".back").closest("div").attr("id"));
});

A:

.closest starts from the current node. But this node haven't got id attribute.
You need to change the selector in in .closest as this:
$(document).ready(function(){
  alert($('.back').closest('div[id]').attr('id'));
});

Now you are searching for a div which has id as an attribute.

