+ 1
Why does not my code work as the the one provided??( in terms of printing the value 0 1 2 3 ...like that ....check the code pls)
https://code.sololearn.com/WqIZL5QGTT9i/?ref=app https://code.sololearn.com/W5wHuejAfLIL/?ref=app
7 Réponses
+ 6
[ ] That's because the JS is executed before the site is loaded. Copy the script and paste it between <script></script> tags at the end of your html file (before the </body> tag)
+ 3
It works if you change it from o=document.getElementsByClassName("g") to o=document.getElementById("g") and change the element's class to id
+ 1
thanks David Carroll Anna
0
Anna when i do it by id its saying cant set 'innerHTML 'to null....
https://code.sololearn.com/WxRU3DJzQtAA/?ref=app
0
[ ] Your new code (‘by id’) works for me.
0
document.getElementsByClassName("g") returns an Array. So, you have to use o[0] in order to access your element:
o[0].innerHTML = ...