There are multiple spans with labels.
<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>
I want to create a function that adds an 'on click' event to detect which span was clicked. For example, clicking the first span should return '0', the second '1'... and so on.
I am aware of using
document.getElementByClassName("viewEdit")
to create an array, but I'm unsure how to identify the clicked span.
I have attempted to find a solution for this question without success. If it has been answered elsewhere, I apologize for repeating it in a different way.