+ 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
4 Answers
+ 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.
+ 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
})
+ 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