I’m adding popups to a mapbox map using:
var popup = new mapboxgl.Popup({closeOnClick: true, offset: [20, 0]})
But how do I remove all popups, for example, with an event listener?
I’ve tried this but it says popup is undefined?:
document.getElementById('mySelect').onchange = function(){
popup.remove()
}
And, tried this, but it just prints an empty element?
document.getElementById('mySelect').onchange = function(){
const element = document.getElementsByClassName("mapboxgl-popup");
console.log("element is", element)
for (el in element) {
console.log(el)
}
}
So what is the best way to remove ALL popups from an existing mapboxgl map?