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

92
Visualizações
Update DOM of popup.html after clicking button

I am making a chrome extension. I want to update a h3 element in popup.html with some text after click a submit button with id submit.

<!-- popup.html -->
<div class="row">
  <h3 id="status"></h3>
</div>
// popup.js
function saveClass() {
    var status = document.getElementById('status')
    status.innerText = 'success';
}

document.getElementById("submit").addEventListener("click", saveClass);

The function populates the element with the text, and I see the text, but it disappears immediately, within some microseconds. Where I am going wrong ?

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

0

For me its' working fine. You can refer the following code snippet

<html>

<body>
    <!-- popup.html -->
    <div class="row">
        <h3 id="status"></h3>
    </div>
    <button id="submit">Submit</button>
    <!-- popup.js -->
    <script>
    
        function saveClass() {
            var status = document.getElementById('status')
            status.innerText = 'success';
        }
        document.getElementById("submit").addEventListener("click", saveClass);
    </script>
</body>

</html>
about 4 years ago · Juan Pablo Isaza Relatório

0

The form refreshes the page by default upon submission, due to which the populated text vanishes. Just add an event listener to disable it, which keeps the DOM intact.

var form = document.getElementById("myForm");
function handleForm(event) { event.preventDefault(); } 
form.addEventListener('submit', handleForm);
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