0
Iam getting an unexpected error ,it says "cannot read property style of null" can anybody please help..?
5 Respostas
+ 8
That's because your code in JS tab loads before your Html.
Put your entire JS code in the below function
this.onload = function(){
//your Javascript code here
}
+ 7
It's the way web codes work in code playground. Your js code is placed in a script in the head tag of your html. It starts executing before your html doc is ready which results in error.
Onload delays code execution till all scripts, stylesheets, pictures are loaded.
You can even try DOMContentLoaded event which will start execution of js code when your DOM is ready.
this.addEventListener("DOMContentLoaded"){
// js code
}
I will link a code demonstrating it later if I find it.
Use a search engine to know why to use on load and similar things.
+ 1
Thanq @Lord Krishna
+ 1
but will you kindly tell me why did this happened. .? because it didn't happened in my laptop...does that happens due to ide or what..?
+ 1
thanq