+ 2
Hello! Why I can't use here in Sololearn sandbox JavaScript method "addEventListener"
addEventListener bug https://code.sololearn.com/Wo2yP85pyXoi/?ref=app
3 Answers
+ 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
+ 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...)
+ 3
You have to wrap the code with window.onload.
Because the JS is running before the DOM or window is loaded.
Solution:
https://code.sololearn.com/Wyxg2YXi8qG0/#js