+ 1

How can I access a span inside <li> in <ol> in JS?[SOLVED]

<ol> <li> <span id="some"></span> </li> </ol> //Js document.getElementById("some").innerHTML = "Text"; This JS code is not working.

26th Mar 2019, 11:53 AM
Sarthak Gupta
Sarthak Gupta - avatar
5 ответов
+ 4
Let me guess... 'Cannot set property innerHTML of null' ? Your script is executed before DOM being loaded properly. Try this: window.onload = function() { document.getElementById("some").innerHTML = "Text"; }
26th Mar 2019, 12:23 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hatsy Rei Thank You so much sir.
26th Mar 2019, 12:44 PM
Sarthak Gupta
Sarthak Gupta - avatar
+ 1
Hatsy Rei Saying Cannot set the propery 'innerHTML' of undefined ?????
26th Mar 2019, 12:34 PM
Sarthak Gupta
Sarthak Gupta - avatar
+ 1
Hatsy Rei Sorry sir, I mistakenly tapped on downvote. Am building a web app. And am facing the problem in function genderWord() Please have a look over this. https://code.sololearn.com/Wg3qbEDHZucB/?ref=app
26th Mar 2019, 12:39 PM
Sarthak Gupta
Sarthak Gupta - avatar