+ 2

Hello! Why I can't use here in Sololearn sandbox JavaScript method "addEventListener"

addEventListener bug https://code.sololearn.com/Wo2yP85pyXoi/?ref=app

19th Jan 2019, 11:58 AM
Istamal Dagalaev
Istamal Dagalaev - avatar
2 Respostas
+ 8
It does only that you need to add window.onload = function(){ //code goes here } Like in this code: https://code.sololearn.com/Wj153VKGavW0/?ref=app
19th Jan 2019, 12:36 PM
Uni
Uni - avatar
+ 5
Javascript needs all html dom elements loaded before doing something with them. Enclosing your code like this: window.onload = function() { // your original javascript code } It means, when all html elements are created and loaded in my browser, I could reference them (adding event listeners, etc...)
19th Jan 2019, 12:47 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar