I have some Javascript, and in one function, I need to get the id of the button that was just clicked. I tried a few things, like this:
var e = window.event,
btn = e.target || e.srcElement;
alert(btn.id);
but that just causes my program to crash.
And this:
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);
};
}
that also just causes my program to crash.
And this:
function functionName(clicked_id) {
alert(clicked_id);
}
that just alerts "undefined".
If I could have some debugging help or just another way to do it, that would be helpful, but it can't have jquery.
Thanks