Javascript to iterate all objects on a page

I know there's a built-in arObj array that contains all the objects on a page, but I cannot figure out how to iterate it. And once I figure that out, I'll need to know how to add objects to it, manipulate objects in it, etc.

To be clear, I know how to do these tasks in javascript; I just do not know the syntax for doing them in Lectora. Any help on those specific questions, or a pointer to an in-depth guide to javascript in Lectora, will be much appreciated.

Discussion (9)

Could you please provide more details as to WHY you want to do that? Maybe there's an easier way?

Also, here's a few starter guides to using JS with Lectora that I wrote: http://trivantis.com/author/lectorasergey/

Sorry, Sergey, somehow I didn't get notified about your reply, so I didn't see it until I logged in for another reason today.

We have about 40 "courses" that consist of 10 to 40 "questions" each, where the "questions" are really topics that learners need to complete from their training plans and the "answers" are "In Progress" and "Complete" or, in some cases, "In Progress" and "Complete / Does Not Apply". (Please don't ask me why we have these!)

Our challenge is that the topics on the training plans change from time to time, and we struggle to keep the courses up to date.

I have automated the creation of a JSON file from a list of topics, and I want to write a script in Lectora that reads that file and populates the questions in a template. A Trivantis developer at the LUC had suggested this could be done at run time; his idea was to publish the courses with blank questions and let the script read the JSON file and populate them when the page loads. This would be incredibly awesome for us, and I just might be able to pull it off -- IF I could figure out how to iterate the objects on the page.

Try running this in a dev console. I prefer Chrome.

for(var propt in arObjs) { console.log(propt); console.log(arObjs[propt]); }

undefined

Darrel, that's interesting -- but I don't see how it helps. I need to be able to iterate the array at run time, in a javascript built into the course.

This script gets every element on a HTML page:

var allElements = document.getElementsByTagName("*");

whether it's of any real use is another question.

In some of my samples i use scripts alike. To parse all elements on a page. Push them into HTMLCollections based upon class and then show in a running version the corresponding indexnumber it has in the particular collection. Usefull when you want to give a user ( or less experienced developer ) access to scripts tweening or changing particular elements on screen.

@Stan /undefinedsmiller7502undefined

,if you are still struggling with this. It shouldnt be too hard to manipulate any element in runtime in Lectora with javascript. I do think best sample i have online here that shows something similar is this one..

http://community.trivantis.com/shared-content/reusable-oop-setup-in-lectora/

It reads all elements on the page in an Array. In later setups i use HTMLCollections, but basically the idea is the same, and this sample shows well how you can target any element on a page...even all if needed...

Regards,

Math

Discussions have been disabled for this post