开发者

Get ID from <td> using jQuery

开发者 https://www.devze.com 2023-01-18 00:12 出处:网络
I have <td id=\"checkb1\" clas开发者_开发问答s=\"checkba\"> I want to get the value of the id when I click on

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

精彩评论

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