Reputation: 22050
I have <td id="checkb1" class="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
Upvotes: 0
Views: 1748
Reputation: 630637
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.
Upvotes: 4