I have an image that i want to change when someone clicks the button above it (from image1.jpg to image2.jpg) I currently have a jQuery that changed the picture but i cant get it to change back if i click the button again.
In addition, I also want it so that, if i were to click on another button that would change another set of images, to have any image that has already been change to go back to their initial image.
Example: I click a button that changed image1.jpg to image2.jpg Then i click a button that changes image3.jpg to image4.jpg, but it also changes image2.jpg back to image 1.
This is my current jQuery:
$(document).ready(function() {
$("#btn1").click(function() {
$("#blue").toggle(function() {
$(this).attr('src', 'images/image2.jpg');
});
});
});
HTML
<button id="btn1"> CLICK ME </button>
<br>
<img id="blue" src="images/image1.jpg">
<br><br>
<button> CLICK ME </button>
<br>
<img id="green" src="images/image3.jpg">