Selecting a particular parent in Jquery


Read {count} times since 2020

If you want to select a particular parent div. Then you should use parents() function. If you use parent() function It won’t work. For Example:
index.html


 

  
 

If you want to get the id of the main parent which is .main then you should use Jquery code like this:

$("#click").live(‘click’, function(){
alert($(this).parents(".main").attr(‘id’));
});

The code above will alert the id of the main parent. Try it out yourself.

Show Comments