I have the following code and this is getting the id attribute of the 'a' element. However, I'd like to get the id attribute of the original '.panel' class.
Any ideas how to do this? Thank you!
jQuery:
$('.panel .panel_content a').click(function(){
alert($(this).attr('id'));
});
Markup:
<div class="panel" id="step_2">
<h3>Title</h3>
<div class="panel_content">
<开发者_如何学编程a href="#">Item</a>
</div>
</div>
$('.panel .panel_content a').click(function(){
alert($(this).closest(".panel").attr('id'));
});
$('.panel .panel_content a').click(function(){
alert($(this).parents(".panel").attr('id'));
});
精彩评论