Forum Discussion
Manipulating the Player Menu with Javascript
Hi Jordan,
You indeed can use querySelectorAll
to get to all elements of a specific type or name.
I have a function in my generic_scripts like this...function doSomething( _accName ){
var targetNodeList = document.querySelectorAll("[data-acc-text='"+_accName+"']");
for(var i=0; i < targetNodeList.length;i++){
//doSomething for all using a terniary operator as if/else check
targetNodeList[i].style.display === "none" ? (targetNodeList[i].style.display = "flex") (targetNodeList[i].style.display = "none");
}
}
Do notice 2 things. querySelectorAll
returns a nodeList, so a list of all elements found. So you need a loop to work with them. Selecting one individual in that list is still possible ofcourse.
And i use a terniary operator instead of a normal if/then statement inside the for loop. The terniary operator can replace a if/then statement in one line.
On Question 3... Yes Javascript is picky on spelling errors. One mistake and it won't work. Storyline compiles all your code allover the project in a user.js file. In the development tools in the browser you can easily debug any mistakes. When an error occurs the console in the browser will give a line number in the user.js file where the mistake is found.
When you donot have errors, you can just click on user.js on the right and the console shows you the line where that is happening. I do think that when you have an error in your code clicking doesnot work and you have to open the tab 'application', find your user.js file...open it up in the console and find the linenumber mentioned. Then you can quickly see what error you made.