I am working on a project using React JS and Leaflet. I am trying to call a function using a button inside a leaflet popup.
A and B are the start and end coordinates.
L.polyline([A, B]).addTo(this.state.map).bindPopup('<button onclick="print()">Print</button>')
print = () => {
// Add some logic here
console.log("Prints")
}
The popup is added with the button but function print isn't being called when the button is clicked.
The error received is Uncaught ReferenceError: print is not defined at HTMLButtonElement.onclick
Many thanks!
you can use jquery like this,
$('button').click(function(){
});
define whatever you want that function to do.