Assign onclick to entire class
I'm trying to attach an event handler on all elements with a specific div.
I have created a jsfiddle showing an example of my code. Could someone
please point me in the right direction?
http://jsfiddle.net/nw4Xs/
var l = document.getElementsByClassName("item").Length;
var foo = function () { alert("foo"); };
for (var i = l - 1; i >= 0; i--) {
document.getElementsByClassName("item")[i].onclick = foo();
}
please no jquery answers
Thanks
No comments:
Post a Comment