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.

1

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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 }); 

Comments

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.