开发者

jQuery get the id from the parent selector?

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'));
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜