Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

349
Vistas
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 Respuestas
Responde la pregunta

0

Try removing return false from button function

button.onclick = function dog() {
    alert("dog");
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda