JSFiddle - React, Tailwind, and code Playground

by Prashant Tapase

HTML

<body>
    <div class='a' style='width:100px; height:100px; background:orange;'></div>
    <div class='a' style='width:100px; height:100px; background:tomato;'></div>
</body>

JavaScript

a = document.getElementsByClassName('a');
l = a.length;
for (var i = 0; i<l; i++)
{
    a[i].addEventListener('onmouseover',analyse); // add event to all classes
}

function analyse()
{
    for (var i = 0; i<l; i++)
    {
        if (this == a[i]) // is this the class that was clicked
        {
            var arg = this; // identified
            anotherFunc(arg);
        }       
    }
}

function anotherFunc(e)
{
    alert(e); // The class that got clicked even though all have the same name
}