Reputation: 8487
<li id="l"><a href="#"><img id="i" /></a></li>
I have image id and i want listitem id , i know one way
$("#i").parent().parent().attr("id");
Is there any better way than this?
Upvotes: 0
Views: 76
Reputation: 318182
$("#i").closest('li')[0].id;
http://api.jquery.com/closest/
Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.
Upvotes: 0