top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between $(document).ready(function() {}) and $(function() { } ?

+1 vote
570 views

Tell me the difference for below two functions

$(document).ready(function() {

    alert("Function using Document Ready");

}

vs

$(function() { 
  alert("Normal function");
}
posted Jul 15, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The two are exactly equivalent: use whichever form you like.

All three of the following syntaxes are equivalent:

$(document).ready(handler)

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

$(handler)

This is the native way.

$(document).ready(function() {
    // code
});

And this is a shorthand for the previous.

$(function() {
    // code
}

);
Refer This Site For More Info
Jquery Official Site for More reference

answer Jul 21, 2014 by Sidharth Malhotra
...