Within a group of span
elements, there are img
tags nested inside.
<span id = "span1" class="span-class">
<img src="img.jpg"/>
</span>
<!--Several more similar span elements -->
<span id = "span123" class="span-class">
<img src="img.jpg"/>
</span>
The image img.jpg
is the default image displayed when the page first loads. I want this default image to be replaced with first_clicked_img.jpg
when I click on a span
for the first time. Subsequently, I would like first_clicked_img.jpg
and second_clicked_img.jpg
to switch places each time I click on a different span
. How can this functionality be achieved using jQuery
, or if simpler, with pure js
?