Skip to content
Advertisement

How to modify href property on Leaflet 1.8 Popup?

Is there a way to modify the href property of the close button on a Leaflet 1.8 popup? I can’t find anything in the documentation for it.

Advertisement

Answer

Unfortunately there is indeed no API in Leaflet for that specifically.

However you can easily customize Leaflet behaviour by modifying how its classes behave.

In your case, you would override L.Popup._initLayout method.

Something like:

L.Popup.include({
  _originalInitLayout: L.Popup.prototype._initLayout, // Keep a reference to super method

  _initLayout() {
    this._originalInitLayout();
    this._closeButton?.href = "#myCustomValue"; // Change the value as desired
  }
});

See also the Leaflet tutorial about extending its classes.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement