+ 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???
2 ответов
+ 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";
}
+ 1
Okay thanks!