Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between $(callback) and $(document).ready(function)?

On the jQuery site, the description for $(callback) was that it behaves the same as $(document).ready(function) but then the examples showed some differences between the two syntaxes. So I was wondering, does anyone know exactly what the differences between the two are?

like image 388
Andrew Avatar asked Dec 17 '22 10:12

Andrew


1 Answers

There are no differences, and the docs don't show any difference:

All three of the following syntaxes are equivalent:

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

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

I think you are confused by the example showing jQuery(function($){ ... }); Which is just a way of calling $(handler), with no $ conflict.

IE.

// Here `$` is used by another library
jQuery(function($){
    // Here `$` refers to jQuery
});
like image 65
Paul Avatar answered Dec 27 '22 20:12

Paul