Yvonne.J.M Yvonne.J.M - 1 month ago 9
jQuery Question

How does $(function(){ }); works?

I have the following code:

function example(){
executing_code;

$(function(){
executing_code;
});

(function(){
executing_code;
})();

};


I know, that the third one is a self-invoking function and I know the meaning of the second too, but the third isn't invoking, when I invoke example()...
Some days earlier it was the other way round and the second didn't worked. I'm confussed.
Now I hope somebody can help me.

Answer
$(function() {

is equivalent to

$( document ).ready(function() {

query api here

Meaning it will fire the code inside the $(function() { when the page has finished loading

You need to close the example() before the $(function() { then call it inside.