I watched a tutorial by this guy - Quentin Watt where he changes an image source whenever he clicks the picture.
There is a picture on the screen when the page opens. Then he clicks the picture and it switches to another picture,replacing the first one. Then he clicks the other one - and it goes back to the first one. And so on…
I have done, in my opinion, the exact same thing,just with different pictures than the ones Quentin used in his tutorial.
But it only works the first time I click it.
The picture changes to the second one. But when I click the second (new) one - nothing happens. There must be something i am not noticing about my code…
I should be using only JavaScript and HTML in order to do this.
Here is my code… Could someone please help?
<head>
<meta charset ="UTF-8" />
<title>The Trick With The Pictures</title>
<script type="text/javascript">
var image_tracker ="h";
function changeit() {
var IMAGE = document.getElementById("hs");
if (image_tracker == "h") {
IMAGE.src = "Sad-smiley.jpg";
image_tracker == "s";
}
else {
IMAGE.src = "Happy-smiley.jpg";
image_tracker == "h";
}
}
</script>
</head>
<body>
<p>
<img id="hs" onclick="changeit();" width="300px;" src="Happy-smiley.jpg" >
</p>
</body>
</html>