I'm new to JavaScript and am having problems with changing an image on my html document. I know that in order to change images, I need to change the src attribute of the img.
I have an image called "magenta.jpg" that I want to replace with "fuschia.jpg" as soon as the page loads.
My HTML
<img src="magenta.jpg" name="photo" id="photo">
My JavaScript
document.getElementById("photo").src = "fuschia.jpg";
When I try doing this, I get an error that says:
Uncaught TypeError: Cannot set property 'src' of null
Could you please help me understand what is going wrong with the code, and how to fix it?