JSFiddle - React, Tailwind, and code Playground
by pamselle
HTML
<body id="example4">
<p>Each of these links should alert 0, 1, and 2 respectively, but they all alert 3.</p>
<ul>
<li><a href="#">Link 0</a></li>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
</ul>
</body>
JavaScript
(function() {
var anchors = document.getElementsByTagName('a');
for (var i=0; i<anchors.length; i++) {
anchors[i].onclick = function() {
alert(i);
return false;
}
}
})();