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

196
Visualizações
asking about basic javascript line by line

As I understand JS code is executed line by line. Why then in the code below alert is performed before hide?

$(document).ready(function(){
    $("button").click(function(){
         $("p").hide();
        alert("The paragraph is now hidden"); 
    });
});
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

That is because the DOM manipulations are usually a bit heavy and are rendered after all the statements in the mentioned event loop are executed.

As @Pointy rightly mentioned, the layout is rendered only after the registered statements are executed.

about 4 years ago · Santiago Trujillo Relatório

0

It is executed after hide(). hide() registers DOM changes which will be executed after your commands are finished. You can wait for a little before you alert:

$(document).ready(function(){
    $("button").click(function(){
         $("p").hide();
         setTimeout(function() {
             alert("The paragraph is now hidden"); 
         }, 100);
    });
});
about 4 years ago · Santiago Trujillo 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