In the previous tutorial, we looked at how to change an image by clicking on it using an onclick event, a function, and the getElementById() method. However, the image would only change once and when we clicked on the image again it would not change back.
In this tutorial, we will be learn how to be able to swap images every time they are clicked. This too will use an onclick event, a function, and the getElementById() method, but will also need an If statement. Watch the video below and then scroll down the page to see the code.
Here is the code:
Next tutorial: Swapping images using an interval timer