Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"); 
    });
});
like image 479
louis Avatar asked Apr 25 '26 13:04

louis


1 Answers

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.

like image 177
atman Avatar answered Apr 27 '26 01:04

atman