getElement js not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
2nd Jun 2022, 12:57 PM
ESLAM YASSER
ESLAM YASSER - avatar
4 Answers
+ 1
Solo Calviղ i found the solution / just need to add script tag at the end of body tag which do what you said 🙂😉
2nd Jun 2022, 9:22 PM
ESLAM YASSER
ESLAM YASSER - avatar
+ 1
window.addEventListener ("DOMContentLoaded", init); function init () { let first = document.querySelector("#one"); console.log(first.textContent); }
2nd Jun 2022, 1:25 PM
Calviղ
Calviղ - avatar
+ 1
onload=()=>{ let first = document.querySelector("#one"); console.log(first.textContent); } The use of onload is necessary to wait for the html-document to be completely loaded, since in SoloLearn JavaScript is loaded first and does not see the tag with id="one".
2nd Jun 2022, 3:32 PM
Solo
Solo - avatar
0
Solo Calviղ sry i didn't get why should I add function ?
2nd Jun 2022, 2:00 PM
ESLAM YASSER
ESLAM YASSER - avatar