+ 1

Error!!!!!

I've given the right Syntax in my JavaScript , but I'm not able to find the error. I'm Confused about what is the error.I've faced this problem alot of time , it's saying that – "cannot read property 'appendChild" of null" !!!!!! , And please tell me the reason behind this error. Here is my code , Please check the error – https://code.sololearn.com/W9QKVnm29usz/?ref=app

28th Jul 2020, 4:49 AM
_Levi_
_Levi_ - avatar
4 Respuestas
+ 7
Replace stars() at last line with: onload = stars; Why↓ https://www.sololearn.com/post/90825/?ref=app JME Explained it well too. Please remember to use search bar 🔍 feature next time to prevent duplicates. This question is frequently asked!! Nice code btw. _K_ I was talking about Sololearn's seach bar. Anyway I'm glad you solved your issue.
28th Jul 2020, 5:03 AM
Kevin ★
+ 4
Adding to what JME said, the most preferred way to wait until the DOM has finished loading is window.onload = function() { // Your code } And through jquery $(function() { // your code })
28th Jul 2020, 5:03 AM
XXX
XXX - avatar
+ 3
It has to do with sololearn running js before html Dom is fully loaded. You have to delay stars until Dom is finished loading so you can properly access document elements. A simple timeout is one way setTimeout(function(){stars();},10) Jquerys $( document ).ready() is another
28th Jul 2020, 4:58 AM
JME
+ 1
JME , Kevin ★ , XXX thanks to you all guys , "kevin ★" , I've searched about it on Google, but i can't find a relevant answer , so I've to ask it , btw thanks for appreciation.
28th Jul 2020, 5:11 AM
_Levi_
_Levi_ - avatar