how can I add more than one ID in the following code?
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
I have tried tried it with querySelectorAll but then no popup shows?
function myFunction() {
var popup = document.querySelectorAll("#myPopup, #myPopup2");
popup.classList.toggle("show");
}
querySelectorAll returns a NodeList which must be traversed through to access each element:
document
.querySelectorAll('#myPopup, #myPopup2')
.forEach(function(element){
element.classList.toggle("show");
})