Why this code works within script tag and not in js in code playground?? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Why this code works within script tag and not in js in code playground??

var obj; obj = document.getElementById("demo"); obj.innerHTML = " Hello";

7th May 2020, 7:43 AM
Tanweer Ahmed Ansari
Tanweer Ahmed Ansari - avatar
5 ответов
+ 5
onload = function(){ //your code here }
7th May 2020, 7:47 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 5
That is because Sololearn by default links out script in head tag . And because of that html elements are not loaded, so you can not select them instead you have to wait for them to load. You have to use onload event described by Mr. Sami Khan
7th May 2020, 7:55 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 2
could you please link the code here in this question?
7th May 2020, 7:57 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 2
Okay, i got it now,... Thank you both Sami Khan and 🔫 Rick Grimes
7th May 2020, 7:59 AM
Tanweer Ahmed Ansari
Tanweer Ahmed Ansari - avatar
+ 1
Hmm, Nice explanation 🔫 Rick Grimes , Deep_Blue
7th May 2020, 8:06 AM
Tanweer Ahmed Ansari
Tanweer Ahmed Ansari - avatar