I'm following a tutorial in the internet to learn some basic Javascript. One of the steps is to have an image change to another one once the user clicks over it, however, it is not working. I've found some tutorials during my research, but all of them include functions that I have yet to learn, so I would like to stick to the tutorial as much as possible.
Here's the JS script:
var myImage = document.querySelector('img');
myImage.onClick = function() {
var mySrc = myImage.getAttribute('src');
if(mySrc === 'images/1.png') {
myImage.setAttribute ('src', 'images/2.png');
} else {
myImage.setAttribute ('src', 'images/1.png');
}
}
Here's the link for the tutorial I'm using: https://developer.mozilla.org/en-US/Learn/Getting_started_with_the_web/JavaScript_basics
And here's the project's Github link: https://github.com/Pedro12909/test