'Onclick not working with button created in JavaScript
I made a function that puts a button in a leaflet popup like
function popUp(feature, json){
myfunc("Cat").outerHTML
};
Here's the function that creates the button
function myfunc(String) {
button = document.createElement('button');
button.textContent = String
button.onclick = function dog() {
alert("dog");
return false;
};
document.body.appendChild(button);
return button
};
The button appears and is clickable in the popup but it doesn't do anything when clicked. I allowed pop-ups in Chrome and even tried it in Firefox but it still won't work.
Also, these two functions are in a functions.js file separate from my index.html file.
Solution 1:[1]
Try removing return false from button function
button.onclick = function dog() {
alert("dog");
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Logu |
