Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!