<button id="rock" class="tools">Rock</button>
<button id="paper" class="tools">Paper</button>
<button id="scissor" class="tools">Scissor</button>
I am trying to get a random button id name and has the following codes
var buttons = document.getElementsByTagName("button");
var buttonsCount = buttons.length;
for(var i = 0; i < buttonsCount; i++) {
buttons[i].onclick = function() {
console.log(this.id);
};
}
But the JSHint validator says Don't make functions within a loop.
(http://jshint.com/docs/options/#loopfunc)
Please note that I want to fix this in plain JavaScript (no other frameworks). Does anyone here know how I get this done?