开发者

Get ID from <td> using jQuery

I have <td id="checkb1" clas开发者_开发问答s="checkba">

I want to get the value of the id when I click on

$('.checkba').click(function() {

    var my_var = $('.checkba').attr('id');
    alert(my_var);

});

The alert shows checkba not the id, checkb1.

Appreciate all assistance.

Thanks Jean


You can use this, to refer to the element you clicked on, like this:

$('.checkba').click(function() {
  alert(this.id);
});

Otherwise .attr() gets the attribute from the first matched element.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜