Yvonne.J.M Yvonne.J.M - 1 year ago 77
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.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download