Forum Discussion
Changing state directly from JavaScript?
I'm back finding that I'd really like to do this again. I'd love to have something like:
player.SetState("nameofobject", "state name");
First steps working properly. Based upon duplicating states for new states. As mentioned in my earlier posts... Storyline makes different HTML when creating the states differently. I do think thats really bad coding...but...it is what it is...
The code below gets an specific element and gets all divs in in it with an data-model-id attribute, thus only the states.
let baseElement = document.querySelector("[data-acc-text='myElement']");
let parent = baseElement.parentNode;
let allDIVS = parent.getElementsByTagName("div");
for (let i = 0; i < allDIVS.length; i++) {
let actualClassName = allDIVS[i].className;
let dataModelID = allDIVS[i].getAttribute('data-model-id');
console.log(i+" : "+actualClassName+" | "+dataModelID);
if(dataModelID != null ){
console.log(i+" dataModelID: "+dataModelID);
}
}
Now you can hide all of them...and show any of them.
Thats for a next one :-)
PS: the statename as is in Storyline is nowhere referenced in the HTML.