Closure in loop
HTML
<a href="#" id="1_Btn" class="button">1</a>
<a href="#" id="2_Btn" class="button">2</a>
<a href="#" id="3_Btn" class="button">3</a>
JavaScript
var buttons = document.querySelectorAll(".button");
console.log(buttons);
function Btn_check(){
for(var i=0; i<buttons.length; i++) {
buttons[i].onclick = (function(n) {
return function() {
alert(buttons[n].getAttribute("id"));
}
})(i);
}
}
setInterval(Btn_check(), 1000/30);