Yvonne.J.M Yvonne.J.M - 5 months ago 40
jQuery Question

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

I have the following code:

function example(){




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.

$(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.