Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try removing return false from button function

button.onclick = function dog() {
    alert("dog");
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!