0

Iam getting an unexpected error ,it says "cannot read property style of null" can anybody please help..?

https://code.sololearn.com/WO5Rl9J5vrDD/?ref=app

12th Feb 2018, 7:33 AM
Vinit
Vinit - avatar
5 Réponses
+ 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 }
12th Feb 2018, 7:38 AM
Lord Krishna
Lord Krishna - avatar
+ 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.
12th Feb 2018, 8:41 AM
Lord Krishna
Lord Krishna - avatar
+ 1
Thanq @Lord Krishna
12th Feb 2018, 8:27 AM
Vinit
Vinit - avatar
+ 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..?
12th Feb 2018, 8:28 AM
Vinit
Vinit - avatar
+ 1
thanq
12th Feb 2018, 9:40 AM
Vinit
Vinit - avatar