+ 1
Why the innerHTML property doesn't work.??!
When i put the innerHTML property in javascript code.. The console of google says (Uncaught TypeError: Cannot set property ' innerHTML ' of null at <document.name> )... I want to know what's the reason and how can i repair the error..???!
5 ответов
+ 4
This mostly happens when you run JS script before HTML loads. Provide your code so that we can clearly help...
+ 2
https://www.sololearn.com/post/99071/?ref=app
You can see an image to my code and problem on this post..
+ 2
Kartik Krishnan
It does't work.
It says (x.innerHTML isn't a function in window.onload )
I don't know what's the error and where???!
+ 1
Alright!
So, the JS shouldn't be like that.
First, you need to let the HTML load.
So, do something like this in the JS file.
window.onload = function() {
//Your code here
};
This runs your JS file only when the window is loaded, i.e. the HTML is done loading along with CSS.
Let me know if it works now!
0
Show the updated code.
It should work