I have several spans labelled.
<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 would like to create a function that adds an 'on click' event which detects which of the spans was clicked. I.e. if the first was clicked first it will return '0', the second '1'... etc.
I realise I can use
document.getElementByClassName("viewEdit)
to create an array, but I am not sure how to detect which one has been clicked.
I've tried to research the question here but suspect I am phrasing it wrong as I can find nothing. Apologies if this a re hash of a similar question answered elsewhere.