Whay js can not set property .innerHTML? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Whay js can not set property .innerHTML?

30th Jun 2018, 7:19 PM
هشام عباس
7 Answers
+ 14
It can. Can you provide your code?
30th Jun 2018, 7:29 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 11
The error probably occurs because the DOM hasn't loaded when he attempts to access it. Donna placed the code at bottom, so it guaranteed it's loaded.
2nd Jul 2018, 5:11 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
thanks Donna☺
30th Jun 2018, 7:59 PM
هشام عباس
+ 2
ohhh....I didnt noticed script tag..i just noticed those two getElementById code
3rd Jul 2018, 5:16 AM
Rohit
Rohit - avatar
+ 1
document.getElementById('new').innerHTML="hello";
30th Jun 2018, 7:34 PM
هشام عباس
+ 1
yes
2nd Jul 2018, 4:05 AM
Rohit
Rohit - avatar
0
Does these two codes make different execution(i mean both are right so why did the first code gave error document.getElementById('new').innerHTML="hello"; ------and-------- var x=document.getElementById('new'); x.innerHTML="hello";
1st Jul 2018, 5:01 PM
Rohit
Rohit - avatar