View Single Post
11-14-2010, 10:45 PM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Originally Posted by Mizko View Post
Ok as i've been going through this book i'm learning about basic functions.

I know that this is the basic format for a function.

function functionName() {
$("p").fadeOut("slow");
}

Then you'll have a button to call it out.

But i'm reading about Creating new HTML Elements and in the explample, why is the function set ou tlike this.

$(function()
{
$("<p>Test</p>")
.insertAfter("#first");
});

Just wondering, what is with the $function() could someone please explain, thanks.
It is a matter of timing, normal JS functions run before the HTML is ready to be messed with. When it is in there jQuery waits until everything is good to go.