+ 1

Why doesn't it recognise the id?

https://code.sololearn.com/Wjb2jxV8C2kp/?ref=app I've made this example code. For some reason, it doesn't get the element with the id. Why???

11th Apr 2019, 6:03 PM
Ric2908
Ric2908 - avatar
2 Answers
+ 6
The DOM isn't completely rendered when the JavaScript runs, that's why JavaScript can't find the element, wrap the code in load event handler function and it will work. window.onload = function() { var hey = document.getElementById("hithere"); hey.innerHTML = "jk"; }
11th Apr 2019, 6:16 PM
Ipang
+ 1
Okay thanks!
11th Apr 2019, 6:21 PM
Ric2908
Ric2908 - avatar