JSFiddle - React, Tailwind, and code Playground
by ZenMaster
HTML
<div><button id ="a1">aa1</button></div>
<div><button id ="a2">aa2</button></div>
<div><button id ="a3">aa3</button></div>
<div><button id ="a4">aa4</button></div>
JavaScript
var add_the_handlers = function(nodes) {
var i;
for (i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function(i) {
var a = i;
return function(e) {
console.log(a);
}
}(i);
}
}
var node1 = document.getElementById("a1");
var node2 = document.getElementById("a2");
var node3 = document.getElementById("a3");
var node4 = document.getElementById("a4");
add_the_handlers([node1, node2, node3, node4]);
//console.log(node1);
//console.log(node1.onclick);