+ 1
DOM manipulation is not working when JS code is in JS part of Solo Learn editor.
When I run the following code to he DOM manipulation doesn't work when the JS code is written in the JS part of Solo Learn editor. But it was working on my computer. When I pasted the code inside the script tag in HTML it is working now. Why doesn't it work when it is written in the JS part of the editor? Is there any problem with the Solo Learn editor or am I missing something? https://code.sololearn.com/Ws38VqsaWZ23/?ref=app.
2 Réponses
+ 2
This problem is related to the order how the code on the JS tab is loaded. It even works differently on different devices. If the script is executed before the main page is loaded and the DOM is incomplete, then it won't work.
Easy fix: on the JS tab enclose all your code in an anonymous function that is bind to the onload event.
window.onload = () => {
// All your Javascript
}
+ 1
Tibor Santa
This is a recurring question. I wonder why the behavior was not implemented by default?