Here is the HTML
<body>
<div>
<button>
Button 1
</button>
<button>
Button 2
</button>
<button>
Button 3
</button>
</div>
</body> (script tag is in right place just left it out here)
Here is my code
(function () {
var button= document.getElementsByTagName("button");
for (var i= 0, len= button.length; i < len ;i = i + 1) {
buttton[i].onclick = function () {
alert(i)};
}
}())
So when I click on each button why are all 3 bringing back a value of 3??? Shouldn't each button bring back a different value??????