Hi,
I have created a long list of items. For each item, there is 1 image. In my case, I use the same image each time.
I would like to use JS to allow users to check an item by clicking on it. Please note, I am not using radio buttons or any other forms.
This is my JS function:
It is triggered using this:
It works for each image. It switches to 2.png when a user clicks on each instance of that image. But how do you make sure it switches back to 1.png on the next click, and so on, effectively creating a switch for multiple instances of the same image?
Thanks!
I have created a long list of items. For each item, there is 1 image. In my case, I use the same image each time.
I would like to use JS to allow users to check an item by clicking on it. Please note, I am not using radio buttons or any other forms.
This is my JS function:
Code:
function changeimage(img, new_src) { var cur_src = img.src.substring(img.src.lastIndexOf("/")+1); if (cur_src == new_src) { img.src = img.old_src; } else { img.old_src = cur_src; img.src = new_src; } }
Code:
<img onclick="changeimage(this, '2.png')" src="1.png" />
Thanks!
Comment