+ 3

Code

Have a trouble, whats wrong with this code? https://code.sololearn.com/WBWosxKe4u3G/?ref=app

29th Dec 2017, 12:16 PM
Botol
Botol - avatar
5 Answers
+ 13
Try this window.onload = function(){ var m = document.getElementsByClassName("ok"); var cl = "#444" m[0].style.backgroundColor = cl; }
29th Dec 2017, 5:32 PM
Ranjan Bagri
Ranjan Bagri - avatar
+ 9
Actually Javascript is loading before body in your code. That's why you getting error.
29th Dec 2017, 6:30 PM
Ranjan Bagri
Ranjan Bagri - avatar
+ 6
@Ranjan yeah, sorry, thanx, it really works, idk why but when i tried it didnt workšŸ˜ž
29th Dec 2017, 6:47 PM
Botol
Botol - avatar
+ 1
You maybe have to wait for the body to be loaded.
29th Dec 2017, 1:29 PM
romangraef
0
Ranjan's answer works for me
29th Dec 2017, 6:34 PM
Nope
Nope - avatar