JSFiddle - React, Tailwind, and code Playground

HTML

<span class="viewEdit">View and edit class one.</span>
<span class="viewEdit">View and edit class two.</span>
<span class="viewEdit">View and edit class three.</span>
<span class="viewEdit">View and edit class four.</span>
<span class="viewEdit">View and edit class five.</span>

CSS

.viewEdit{
    display:block;
    padding:3px;
    border: 1px solid #CCC;
    width:250px;
}

.viewEdit:hover{
    cursor:pointer;
}

JavaScript

var elements = document.getElementsByClassName("viewEdit");

for (var i = 0; i < elements.length; i++) {
    (function (index) {
        elements[index].addEventListener("click", function () {
            for (var x = 0; x < elements.length; x++) {
                if (elements[x] === this) alert(x);
            }

        }, false);
    })(i);
}