+ 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 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.
+ 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