I have a problem I can’t solve…
I have a DIV that contains a heading and two or more tags.
Each tag is visible when it is switched to “on” in the CMS (conditional visibility).
Now I would like to achieve to hide the entire DIV when all switches are “off” (-> no tags to display).
Conversely, this means that the DIV is displayed when one or more switches are “on”.
Can someone maybe help me with this?
Thanks in advance!
Like @webdev mentioned, you’ll need to create a sample project so we can check out the setup within the Designer before we can help.
There are a few different ways I can imagine this being setup (each with their own solution) and unfortunately giving us code snippets doesn’t provide enough context.
<script>
// get all children of all .div-block-3 elements that have the class .group
document.querySelectorAll('.div-block-3 > .group').forEach((el) => {
const tag = el.querySelectorAll('.div-block-2 > .div-block');
// check if all tags have style "display: none"
let hasVisible = false;
tag.forEach((el) => {
const style = window.getComputedStyle(el);
if (style.display !== 'none') {
hasVisible = true;
}
})
if (!hasVisible) {
el.style.display = 'none';
}
})
</script>