Reputation: 6199
I have a image inside a div when i click on the image i want it to alert me of the parent id that will be "group1"
<div id="group1">
<img class="header_logo_dis" src="test.png">
</div>
$('.header_logo_dis').click(function() {
alert($(this).parent("div:first"));
});
Thank you,
Upvotes: 3
Views: 28416
Reputation: 238045
Or to be extra efficient and skip jQuery altogether:
alert(this.parentNode.id);
Upvotes: 19