Why can't I use "document.getElementById" in catalog item's client script

Allen17
Tera Contributor

error log: TypeError: Cannot read property 'getElementById' of null,I didn't check the Isolate script

11 REPLIES 11

paulocress
Kilo Explorer

This error TypeError: document.getelementbyid(...) is null would seem to indicate that there is no such element with an ID passed to getElementById() exist. This can happen if the JavaScript code is executed before the page is fully loaded, so its not able to find the element. The solution is that you need to put your JavaScript code after the closure of the HTML element or more generally before < /body > tag.

 

Eric Woody
Tera Expert

In case anyone comes through and needs a solution that worked for me, I just added a pause to the client script to allow time for the element to be created. Example:

 

setTimeout(function() {
 //whatever code needs to be delayed so the element can be created
}, 500);