0

I copied the JS in this code from W3 schols. Why am I getting an error?

https://code.sololearn.com/WErF2c5rH78h/#html Getting an error on line 6. Why?

11th Jun 2018, 10:26 PM
Daniel Cooper
Daniel Cooper - avatar
3 Antworten
+ 2
Because you cannot access to an element DOM with js if its not loaded... You have to make sure that any access to DOM happen after its loaded (at example in window.onload listener)... in your case remove the function call w3CodeColor and add it in window.onload= function(){ // add here }
11th Jun 2018, 10:52 PM
KrOW
KrOW - avatar
11th Jun 2018, 11:00 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
0
https://www.w3schools.com/howto/howto_syntax_highlight.asp This is where I got the code from.
11th Jun 2018, 10:27 PM
Daniel Cooper
Daniel Cooper - avatar