1

i wanted to know difference between both.

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

You guys might call me stupid but i don't know why its happening.

well here is problem.

When i use (function($){ then i can't see any result in console.log but it's showing all console debug result when i use document.ready.

I am using jQuery v1.8.2.

Thanks.

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90

3 Answers3

2

the first one

$(function(){...});  //missing $ sign here in your code

this is just a shorcut to call document.ready in Jquery.. both is exactly the same.. if you happen to see the core .. you will notice this in a comment...here is the link

bipen
  • 36,319
  • 9
  • 49
  • 62
1

The code

(function($){
    //some console.log code     
});

should be like that

$(function() {
    //some console.log code     
});

Now test it.

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

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
1

You missed something at the closing in the first example:

(function($){
    //some console.log code     
})(jQuery); // <----------add (jQuery) here and test it

or this:

  jQuery(function($){ // <---------add jQuery first here
    //some console.log code     
  });
Jai
  • 74,255
  • 12
  • 74
  • 103