How does jQuery.ready () handle the call to itself?

As an example:

$( function(){
    //do stuff
    $( function(){
        //do other stuff
    });
});

Of course, written in code, this does not seem to make any sense. But a plugin that works with HTML elements can use .ready (), and it runs on the element in the main script.ready (). How exactly does this handle jQuery? It obviously works, but is it doing anything special?

+5
source share
1 answer

If .ready () is called after the DOM initialization, the new handler will be executed immediately.

This means that when the first function is executed, the internal one will be executed immediately.

In addition, jQuery allows you to associate several functions with one event and will call them all (provided that no one throws an error)

, :

jQuery(document).ready(function(){
        for(i=0;i<1000000;i++);
        console.log('2');
    });
console.log('1');
+2

All Articles