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

158
Visualizações
How to addEventListener to a button in popup content of ArcGIS API for JS

I have created a custom popup with the popupTemplate function with ArcGIS JS API 4.x

And i add a button in popup content by html.

but i can not addEventListener to a button in popup.

here is the way i am try to do now: ((the full code is here:https://codepen.io/llllllllc/pen/mdpabGw))

  1. return html to create button in popup content
const popupTemplate = {
                // autocasts as new PopupTemplate()
                title: "Population in {NAME}",
                content: populationChange,
                };

                layer.popupTemplate = popupTemplate;

                function populationChange(feature) 
                {
                    const div = document.createElement("div");
                    div.innerHTML =
                        "<input type='button' id='btn' value='CLICK'>";
                    return div;
                }
  1. watch content change
view.popup.watch("content", (newValue, oldValue, propertyName, target) => {......});

3.querySelector("#btn") then addEventListener but it fail ,and console.log(btn) show btn is null

const btn = document.querySelector("#btn");
console.log(btn)
btn.addEventListener(
    "click",
    function () {
        lert("HELLO WORLD!");
    },
   false
);

the consol show like this picture

Any help much appreciated!!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i think i figure it out !

i try to do querySelector to "const div" before it return and it works!

const div = document.createElement("div");
div.innerHTML ="<input type='button' id='btn' value='CLICK'>";
const btn = div.querySelector("#btn");
btn.addEventListener(......);
return div
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