Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

351
Visualizações
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 Respostas
Responde à pergunta

0

Try removing return false from button function

button.onclick = function dog() {
    alert("dog");
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda