<button id="1">Button 1</button>
<button id="2">Button 2</button>
<button id="3">Button 3</button>
var reply_click = function()
alert("Button clicked, id "+this.id+", text"+this.innerHTML);
document.getElementById('1').onclick = reply_click;
document.getElementById('2').onclick = reply_click;
document.getElementById('3').onclick = reply_click;
@JasonLeBrun I don't know what is the id of the element that I am gonna click. That's what I am looking for. A code draws a SVG element and when I click on it, I need to know it's "id" attribute. If and how can this code be used?
When an event handler is called, it's called within the context of the element that was clicked on. So, the identifier this will refer to the DOM element that you clicked on. You can then access attributes of the element through that identifier.
what if the buttons are in a repeater and therefore generated dynamically, so you dont know how many buttons you will have?