0

Possible Duplicate:
Different forms of $(document).ready
What is the difference between these jQuery ready functions?

What is the difference between the following two functions?:

$(function() { });

and

$(document).ready(function(){});
Community
  • 1
  • 1
L84
  • 45,514
  • 58
  • 177
  • 257

1 Answers1

0

.ready is a handler function for use once the DOM is ready The .ready() method is generally incompatible with the attribute. I would use $(function() {}); normally.

$(document).ready(function(){}); is typically used for anonymous functions

All three of the following syntaxes are equivalent:

$(document).ready(handler)
$().ready(handler) (this is not recommended) 
$(handler)

http://api.jquery.com/ready/

Jashwant
  • 28,410
  • 16
  • 70
  • 105
user1588670
  • 283
  • 1
  • 3
  • 13
  • 3
    `The .ready() method is generally incompatible with the attribute.` What exactly does this mean? – Anirudh Ramanathan Sep 21 '12 at 05:05
  • looks like they took that text directly from the [jQuery documentation](https://api.jquery.com/ready/), where the full sentence reads "The `.ready()` method is generally incompatible with the `` attribute." The following text, outlining the three ways of wiring up a DOM ready handler, is also from the documentation. – Paul d'Aoust Jun 02 '15 at 23:25