Close All Popups with Leaflet.js Close All Popups with Leaflet.js javascript javascript

Close All Popups with Leaflet.js


There is a clean method from your map object to close all open popups

map.closePopup();


I managed to solve my problem by this piece of code:

$(".leaflet-popup-close-button")[0].click();

Hope it helps someone in future.


Just remove your calls to .openPopup().

Instead of

L.marker([57.70887, 11.97456]).addTo(map).bindPopup("<b>Ideal Festival</b><br />2004").openPopup();

Use

L.marker([57.70887, 11.97456]).addTo(map).bindPopup("<b>Ideal Festival</b><br />2004");

The click behavior will still be there (when users click on those markers, the popups will still appear), but the popups won't be visible when the page loads.