Closing all popups


(Paula) #1

Hi!
I’m using JavaScript to open and close popups in a scroll page. I want to close all popups that are opened when I open another popup. I searched and I find a Close button but that’s not what I need, I need that all buttons automatically close the other windows when one is open.

This is my archive
https://drive.google.com/open?id=1QWJVHKPHcJ-SpElaI0kzBTDbrOf-7-k6


(Jonathan Deutsch) #2

It looks like you are generally using code like this to toggle the display hidden elements:

var elements = document.getElementsByClassName('pp17');
for (var i = 0; i < elements.length; i++) {
    elements[i].style.display = elements[i].style.display == 'block' ? 'none' : 'block';
}

You could just add onto those similar code which hides the elements in the other popups you do not want to show:


// show 17 - same as before
var elements = document.getElementsByClassName('pp17');
for (var i = 0; i < elements.length; i++) {
    elements[i].style.display = elements[i].style.display == 'block' ? 'none' : 'block';
}

// hide 18 - always set to none
var elements = document.getElementsByClassName('pp18');
for (var i = 0; i < elements.length; i++) {
    elements[i].style.display = 'none';
}

// hide 19 - always set to none
var elements = document.getElementsByClassName('pp19');
for (var i = 0; i < elements.length; i++) {
    elements[i].style.display = 'none';
}

There are also methods to do this without code in Hype, but this would be one JS answer.


(Paula) #3

Thank you so much @jonathan ! I’m gonna try it!!