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

227
Visualizações
How can I get elements inner text after dom is being refreshed after the submit button?

I'm working on automating a task (filling a form and submitting data then getting the result message where the data is being read from a txt file line by line). While running my JS code via the console, everything works fine until before the clicking on submit button. after the click on the submit button, I can see the HTML is being reloaded with new data and the URL is changed from www.example.com to www.example.com/requests/12345 and then the next step after the click is not respected.

I thought may be because I was using:

document.getElementByID("btn-submit").click();

and changed it to

$("#btn-submit").click().trigger('change');

But still same issue.

I tried to use sleep functions and setTimeout to wait for the new HTML to load but this didn't help at all :(

The task is simple steps until button click all works perfect, I'm stuck only at after the submit button as I want to get the results that shows on the page after clicking the submit button.

Any ideas please what is being done wrong from my side?

The Elements I'm trying to get are in a div that is empty before the submit button is being clicked like this

<div id="message-bar">


</div>

After the submit button is clicked it is filled like the below (also the URL is changed to something link www.example.com/requests/12345 - of course the result elements won't show if the button is not clicked:

<div id="message-bar">
    <div id="alert-success" class="alert alert-success">
      <button type="button" class="close" data-dismiss="alert">×</button>
      <div class="text alert-text">Request approved!</div>
      <ul id="bullet-items"><li>Thank you</li></ul>
    </div>
</div>

I tried to check if the element is not empty, then get the elements innerText, but seems like my code is being removed when the page URL changes after the submit button:

    if (document.getElementById("message-bar").innerText != "") {
          // do something
    } 

Thank you so much

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

0

Try using the .preventDefault() event

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault).

about 4 years ago · Juan Pablo Isaza Relatório

0

Try

$("#btn-submit").click(function(event){
    event.preventDefault();
})

Or without jQuery

var btn = document.getElementById('btn-submit');

btn.addEventListener('click',function(event){
    event.preventDefault();
})
about 4 years ago · Juan Pablo Isaza Relatório

0

From what I understand you need the content not after the click, but after what the click is triggering. Here’s the same Q, answered. Basically you wait for the mods to happen then “read” the element content.

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