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.
So technically they are both the same. Not major difference between these two declaration. They used based on weather you use JavaScript then you should use $(document). ready declaration in other case you use jQuery library which is a part of JavaScript then you should use $(function) declaration.
load(function(){ // ...}) @undefined, this is almost the same as $(document). ready(function(){ ... }) . load() will wait until the graphics are also loaded.
ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc. are loaded, but after the whole DOM itself is ready.
ready' function in a page? Can we add more than one 'document. ready' function in a page? Yes we can do it as like I did in below example both the $(document).
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With