How to get ID of button user just clicked?

html, javascript, jquery

Solution

$("button").click(function() {
    alert(this.id); // or alert($(this).attr('id'));
});

Problem

Possible Duplicate: Getting the ID of the element that fired an event using JQuery I have many buttons with ID attribute. ``` <button id="some_id1"></button> <button id="some_id2"></button> <button id="some_id3"></button> <button id="some_id4"></button> <button id="some_id5"></button> ``` Assume the user clicks on some button, and I want to alert this ID of the button the user just clicked on. How can I do this via JavaScript or jQuery? I want to get the ID of button user just clicked.

Original source

Related problems