0

Changing html with JavaScript

Where's the problem in this code https://code.sololearn.com/W7kWuF8ae4vI/?ref=app?

21st Mar 2018, 6:26 PM
Evil Dog
Evil Dog - avatar
3 odpowiedzi
+ 1
There are two problems with your code! #1: you used document.getElementsById() instead of document.getElementById() ...the Element should not contain "s" since "Id" is singular not plural like "ClassName or TagName" #2 you must either add your function(s) inside the html element <script> tag or wrap all your function(s) up in "window.onload" since you wanted to get something out of the DOM or WINDOW ...heres a modified version of your code. https://code.sololearn.com/WsuM3dYda9TJ/?ref=app
21st Mar 2018, 7:31 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 1
So, "window.onload" is obligate, when we're working with DOM?
21st Mar 2018, 10:00 PM
Evil Dog
Evil Dog - avatar
0
You need to put the part of your code where you collect the user input anf call the function red blue or green in a function. You then need to set that function equal to window.onload The cide fails because the FOM has not finished loading so document.getElementById("main") returns null.
21st Mar 2018, 7:32 PM
josh mizzi
josh mizzi - avatar