Reputation: 1643
Short question from a jQuery newbie:
Say I'm receiving an arry of json objects and my script generates a table row (the last td contains a button) in an existing table for each one of them. The index will be the id of the and the class is "delete".
This works so far:
$(document).on('click', ".delete", function(){
alert('you clicked me!');
});
But I need the id of that button the send the delete request for the right object. How would I do that?
Upvotes: 0
Views: 222
Reputation: 57105
$(document).on('click', ".delete", function(e){
alert('you clicked me!' + e.target.id);
});
Upvotes: 2
Reputation: 28528
this
keyword will help you.
$(document).on('click', ".delete", function(){
alert('you clicked '+ this.id);
});
Upvotes: 1
Reputation: 388316
you can use this.id
because this
inside the event handler refers to the target dom element.
$(document).on('click', ".delete", function(){
alert('you clicked me!' + this.id);
});
Upvotes: 4