Reputation: 27
I have trying to change my code with .setAttribute too, the same thing appear..
In Javascript
document.getElementById("MyImg").src = "./sea.jpg";
In HTML :
<img src="./earth.jpg" id="MyImg">
Thank you for any futer answer !
Upvotes: 0
Views: 2807
Reputation: 355
Uncaught TypeError: Cannot set property 'src' of null
The null is the important part. Your DOM search (getElementById) failed.
Some ideas off the top of my head:
If you need an example to work off of: https://www.w3schools.com/jsref/prop_img_src.asp
Upvotes: 2