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

157
Visualizações
Onclick is only triggered once after assigning functions through for loop

In those for loop, I am assigning a function to a close button that will essentially remove a mark tag from some text.

    for (q = 0; q < json_response.trainer.annotation.length; q++) {
        let close_ = document.getElementById(`cl_${x3}_${q}`);
        console.log(close_)
        close_.onclick = function () {
            delete_ent(this);
        };
    };


function delete_ent($this) {
    let all_text = $this.parentNode.parentNode.innerHTML;
    console.log($this, $this.parentNode);
    let test1 = $this.parentNode.innerHTML;
    let replace_text = test1.split("<span>");
    // console.log(replace_text[0]);
    let updated_text = all_text.replace(`${$this.parentNode.outerHTML}`, `${replace_text[0]}`);
    $this.parentNode.parentNode.innerHTML = updated_text;
}

It works exactly as intended for the first mark tag removed, but then after it's updated the text, the other close buttons stop working.

This is for a chrome extension

about 4 years ago · Juan Pablo Isaza
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