For some reason I am keep on getting a syntax error from this "innerHTML", can someone help me?
HTML CODE:
<div id="ID"></div>
JavaScript CODE:
document.getElementById("ID").innerHTML = "Test";
Syntax Error: Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')
I am trying to make the div respond with a "Test" using "innerHTML" and "getElementById" but the syntax error is getting in the way.
The error means that js not found with the selector ID. You need ID as a selector. Take a look:
document.getElementById("ID").innerHTML = "Test";
<div id="ID">Hello</div>
The error refers to the fact that document.getElementById("ID") is invalid. Meaning that "ID" is not existing. In your HTML code there needs to be an object with the id="ID".
Running getElementById on an ID that isn't currently existing on the webpage will give you this error, if you are working on a project with multiple scenes and you try to call this for an element on a scene that is NOT currently shown on the screen it will error out with this error.