I wrote a script inside the innerHTML of a Text element. I was geeting this error while trying to access other element's data using the Hype API:
ReferenceError: Can't find variable: hypeDocument
Later, I did the same thing using jQuery without an issue. How to solve this issue for the Hype API? Please see the attachment to understand the issue. Thanks!
document.getElementById('id').innerHTML = 'Got the hypeDocument reference!';
But the API is a non-starter... in the console the following appears:
APPLY ERR w=Please check the innerHTML of this element
<script>
hypeDocument.getElementById('id').innerHTML = 'Got the hypeDocument reference!';
</script>
: ReferenceError: Can't find variable: hypeDocument
i.e. this script runs before Hype’s API establishes its bona fides.
<script> tags within inner HTML are executed in the global/window scope and thus do not have a hypeDocument object – it is the same if you were executing on the head.
You can reference it via HYPE.documents["documentName"] (though this is dependent on your export) or capture the global variable at an early time such as On Document Load with head HTML code that would look like this: