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
index.html
<div class=main id=p1>If you want to get the id of the main parent which is .main then you should use Jquery code like this:
<div id=p2>
<div id=p3>
<a id=click>This is the a tag!!</a>
</div>
</div>
</div>
$("#click").live(click, function(){The code above will alert the id of the main parent. Try it out yourself.
alert($(this).parents(".main").attr(id));
});
download file now
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.