Why can't I use "document.getElementById" in catalog item's client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 11:31 PM
error log: TypeError: Cannot read property 'getElementById' of null,I didn't check the Isolate script
- Labels:
-
Service Portal Development
- 4,780 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2021 09:18 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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: