Custom JavaScript not Recognizing Object Names

Hello Rockstars,

I'm using Lectora Online and am trying to implement custom javascript. When I reference an object using getDisplayDocument().getElementById("[objectName]") in the Run Custom JavaScript field it returns an error that the referenced object is 'null'. This happens whether I use the name I have given it or use the HTML name assigned by Lectora.

I have managed to get text objects to work, but only by accessing the HTML and manually adding id="[objectName]" as an attribute to the

tag. Am I missing something simple here?

Discussion (3)

(I don't personally use this much, so pardon me if I'm off-base) - are you accessing the items like this, or using another method?

You can setup a JavaScript variable that points to the Lectora object.

For example:

Button GREEN

(add an action to the button)

On Page Show -> Run JavaScript -> getDisplayWindow().greenButton = %HTMLNAME%;

To show the button from JavaScript:

getDisplayWindow().greenButton.actionShow();

To get to the Lectora object DOM structure reference the object's div element:

console.log(getDisplayWindow().greenButton.div.id);

https://rockstars.elearningbrothers.com/discussion/comment/454293#Comment_454293

Cainam - Thanks for your reply. Yes, that was one of the ways I tried to access the items without any luck. I really appreciate your response, though.

Wheels - That helps! I gave your example a try and it worked. So going forward I'll follow that format - setting up a variable for objects that I want to work with. Thank you very much!!