jQuery and $

by Sanju 2012-09-14 12:29:43

jQuery and $

Ever wonder why/how you can use jQuery and $ interchangeably? To find your answer, view the jQuery source, and scroll to the very bottom.

There, you'll see:

window.jQuery = window.$ = jQuery;


The entire jQuery script is, of course, wrapped within a self-executing function, which allows the script to limit the number of global variables as much as possible. What this also means, though, is that the jQuery object is not available outside of the wrapping anonymous function.

To fix this, jQuery is exposed to the global window object, and, in the process, an alias - $ - is also created.

Tagged in:

609
like
0
dislike
0
mail
flag

You must LOGIN to add comments