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.
精彩评论