How to get ID of button user just clicked?
With pure javascript:
var buttons = document.getElementsByTagName("button");
var buttonsCount = buttons.length;
for (var i = 0; i <= buttonsCount; i += 1) {
buttons[i].onclick = function(e) {
alert(this.id);
};
}
http://jsfiddle.net/TKKBV/2/
$("button").click(function() {
alert(this.id); // or alert($(this).attr('id'));
});