JSFiddle - React, Tailwind, and code Playground

HTML

<span class='text'>1</span>
<span class='text'>2</span>
<span class='text'>3</span>

CSS

.text{
    width:20px;
    height:20px;
    border:1px solid black;
}

JavaScript

var textSpans=document.querySelectorAll('span.text');
for (i in textSpans)
{
    textSpans[i].onclick=function() {alert(i);};   
}