jQuery $( function() {} ) and $(document).ready the same?

javascript, jquery

Solution

See the extract below from http://api.jquery.com/ready/

All three of the following syntaxes are equivalent:

- `$(document).ready(handler)`

- `$().ready(handler)` (this is not recommended)

- `$(handler)`

Problem

To have a working datepicker on a field, I have to put this script inside my element ``` $( function() { $( "#date_datepicker" ).datepicker( { dateFormat: "yy-mm-dd" } ); }); ``` Removing the `$( function() {` makes the datepicker not work. So does it mean that the `$( function() {` is the same as `$(document).ready`? I'm trying to optimize my javascript codes so knowing this might help.

Original source

Related problems