Skip to content Skip to sidebar Skip to footer

What Does The Jquery() Function In Jquery Do?

In this video there is a snippet of code that goes something like this: if (jQuery) {jQuery(function() { // ... })} I've never seen the jQuery() function before (then again, I

Solution 1:

$() is an alias for jQuery(), defined as:

// Expose jQuery to the global objectwindow.jQuery = window.$ = jQuery;

http://code.jquery.com/jquery-1.4.js

there is a special case defined when $() or jQuery() is called with the first argument being a function:

// HANDLE: $(function)// Shortcut for document ready
} elseif ( jQuery.isFunction( selector ) ) {
    return rootjQuery.ready( selector );
}

sometimes $ can conflict with other libraries (like prototype) that define the same function, so if you call

jQuery.noConflict();

it will remove the $ alias, setting it back to the original value found, essentially:

window.$ = _$;

Solution 2:

jQuery(function()

is same as

$(document).ready(function()

if(jQuery)

is a check whether the jQuery.js file has been loaded or not.

There is another way to check this

if (typeof jQuery == 'undefined')
{
    //jQuery has not been loaded  
}

Solution 3:

The $ function is an alias for the jQuery function. So, they are the same.

If you use jQuery in noConflict mode, there is only jQuery() function

Solution 4:

I think it is the same that using $() but you use jQuery() for compatibility with other libs which also use $()

jQuery can be a variable that store a function. Guess that if is to check if it is not undefined or something like that

Post a Comment for "What Does The Jquery() Function In Jquery Do?"