Why doesn't 'document.getElementById' work for me, I've tried all other methods and still not working. Please help me out🙏 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why doesn't 'document.getElementById' work for me, I've tried all other methods and still not working. Please help me out🙏

I tried the same code on my PC and it worked well, what's happening, is it Sololearn? Plus I see others post with the same code and it works for them🤷 https://code.sololearn.com/Wqum3SV4cnHw/?ref=app That's the link to the code

23rd Jun 2020, 1:22 PM
Express
Express - avatar
3 Answers
+ 5
Here js script gets loaded before html ,so getting element that doesn't exist raises error which I am assuming is your case ,if so add all your js code in window.onload=function(){ } Or you can simply add script in html before closing body tag
23rd Jun 2020, 1:45 PM
Abhay
Abhay - avatar
+ 3
Do you have a copy of that code here in SoloLearn? If you do, I suggest you to share that code link in your thread Description, so everyone can check for a problem. See this guide in case you didn't know how to share links here 👇 https://www.sololearn.com/post/75089/?ref=app
23rd Jun 2020, 1:38 PM
Ipang
+ 2
Thank you Abhay
23rd Jun 2020, 1:53 PM
Express
Express - avatar