How to change html image to another by JavaScrip?
<html>
<body>
<h1>Changing HTML image</h1>
<img src="off.jpg" id="idea" width="100"/>
<button type="button" onclick="
document.getElementById ('idea')
.src='on.jpg'">on</button>
<button type="button" onclick="
document.getElementById ('idea')
.src='off.jpg'">off</button>
</body>
</html>
The image below has two buttons. If you click on the light bulb will on, if you click off the light bulb will off.
This is done by the same method used to change text. But instead of .innerHTML we will use .src for the source of the image
that should change. So each and every time we click the button it will change the image to on and off.