+ 1
Please can you tell me what is the problem of this code?why omar dosent change to ola?
12 Respuestas
+ 2
It's because you defined the variabld before the page loaded, therefore it will be null.
window.onload = () => {
document.getElementById(1) = "oma";
}
Also note that using numbers for ids is a bad practice
+ 1
Which var i defined?!!
And also i worte what u say in the code and i still have the problem....you can see the code
+ 1
Did you forget to write innerHTML ?
+ 1
Yes, I did, but you forgot to write the arrow sign :/ (=>)
+ 1
Ok thanks☺
+ 1
Airree you said that my code didnot run because i defined the variable before the page loades
Which variable
?
+ 1
I guess I wasn't really paying attention. I just meant that you tried to get an element which didn't exist yet
+ 1
How it didnot exist yet?!
I wrote it in html body ??
+ 1
No, it just means it didn't exist at the time you ran the function, because the page wasn't loaded.That's why you should use the window.onload function, which will only run when the document is loaded
+ 1
You mean that when i click "run" .... js codes is runs first...then html ?
+ 1
Yes, kind of
+ 1
Ok thanks alot