Wednesday, August 30, 2017

Selecting a particular parent in Jquery

Selecting a particular parent in Jquery


If you want to select a particular parent div. Then you should use parents() function. If you use parent() function It wont work. For Example:
index.html
<div class=main id=p1>
 <div id=p2>
  <div id=p3>
    <a id=click>This is the a tag!!</a>
  </div>
 </div>
</div>
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.

download file now

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.