Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery document.ready multiple declaration

I realized that I can specify $(document).ready(function(){}); more than once.
Suppose like this

$(document).ready(function(){
    var abc = "1122";
    //do something..
});

$(document).ready(function(){
    var abc = "def";
    //do something..
});
  1. Is this standard ? Those codes work on my FF (16.0.2). I just a little afraid that other browser may not.
  2. What actually happen ? How jQuery handle those code ?

Thanks.

like image 264
Hendry H. Avatar asked Dec 20 '22 12:12

Hendry H.


1 Answers

Yes, it's standard and recommended and jQuery guarantees those functions will be executed in order of declaration (see this related answer for details regarding the implementation).

The abc variable are local to your functions and don't interfere. You cannot see the value of abc declared in one of the callbacks from the other one.

like image 57
Denys Séguret Avatar answered Dec 29 '22 00:12

Denys Séguret