Forum Discussion
davelees
3 months agoCommunity Member
Javascript issue
I found some script that will move an object to the highest Z index from a master slide, this works fine for one object but I need the script to do it for 3 objects.
let controls = document.querySe...
- 3 months ago
You can't declare "controls" variable multiple times. You have to use different variable names for each object. There are three options to do it:
Option 1
It updates your initial codelet controls01 = document.querySelector("[data-model-id='60O8MBAYLcA']"); controls01.style.zIndex = "9999"; let controls02 = document.querySelector("[data-model-id='689jgbOitBP']"); controls02.style.zIndex = "9999"; let controls03 = document.querySelector("[data-model-id='6R7jmOoLVUg']"); controls03.style.zIndex = "9999";
Option 2
A more efficient way to avoid redundant, repetitive lines of code from Option 1let controls = ["6QRrSIXWFTI", "5o24oXaoCNj", "5jkOK4Yq1d3"]; controls.forEach(control => { let controlId = document.querySelector(`[data-model-id='${control}']`); controlId.style.zIndex = "9999"; });
Option 3
If possible, group all objects on the master slide and use the data-model-id of the group.let controlsGroup = document.querySelector('[data-model-id="6lNdgNGW4o0"]'); controlsGroup.style.zIndex = '9999';
naps2
3 months agoCommunity Member
To adjust the script for multiple objects, use an array to store the elements and loop through them to set the zIndex for all at once. It then becomes cleaner and more manageable code.