+ 8
How to change the source of an image using external js?
I am trying to change the image source of an image using external js like this:- var image = document.getelementbyId('image'); Image.src = 'newimage.src'; But it shows an error can't access the src value of null. But the same code works fine using internal js. Please help me!
3 Answers
+ 5
You have to wrap your js codd inside the window.onload function to get rid of the null element message.
window.onload = () => {
//your code
}
+ 3
Its the usual problem of accessing to dom when is possible... See this code
https://code.sololearn.com/WlA8Fx8bl6nI/?ref=app