Reputation: 4303
My goal is to target unique id of a button using jquery.
For example
<button id="5412313">Remove</button>
<button id="9882813">Remove</button>
<button id="123123123">Remove</button>
<button id="214343">Remove</button>
<button id="3434343">Remove</button>
<button id="4343434">Remove</button>
Jquery
$("#WhatshouldIputInHere?").on("click", function(){
console.log($(this));
});
Upvotes: 0
Views: 209
Reputation: 172
You can use event
object in the handler function, the code is like this:
$('button').on('click', function(event) {
alert(event.target.id);
})
Here's the effect of the code above
Upvotes: 1
Reputation: 3530
You can try with remove()
.
$("button").on("click", function(){
$(this).remove();
//$(this).attr('id');
});
Based on your button label i came to know this.you can do anything with your id which i have commanded .
Upvotes: 1
Reputation: 110
$('button').on('click',function(){
console.log($(this));
if($(this).attr('id')=='9882813'){
console.log('button with id '+$(this).attr('id')+'clicked');
}
});
Upvotes: 0