Reputation: 23
I am using Leaflet and I have several markers on the map. I am trying to trigger a click event so that when I click on one of the markers it will scroll to a div
down the page
For example, the marker is created like this:
var marker = L.marker([ 51.5, -0.09 ]).addTo(map);
Can I add a click event to this?
Upvotes: 0
Views: 499
Reputation: 181
You can bind event on your marker when you initialize it. When the click is fired you just redirect to the dom element you want :
var marker = L.marker([51.5, -0.09]).addTo(map).on('mouseover', () => {
document.location.href = "#id_of_div";
});
Upvotes: 2