1

I realize that the $ is just sort of a convention for naming variables pointing to jQuery objects, and is also the function for document.getElementById(), but does function($) mean anything?

Edit: I actually meant

(function($) {
    /* ... */
})(jQuery);

Sorry for the confusion, but thanks for the answers.

2

3 Answers 3

4

Some code uses $ for jQuery (or other libraries) to keep the global scope clean. By default, jQuery takes over $ in the global scope, however, if extensions and whatnot avoid using the global $, it can keep the scope clean, along with helping jQuery work with other libraries.

(function ($) {
    //$ is now a jquery instance
})(jQuery);

Basically it's a way to instantly execute code with a jQuery object without the function depending on a global-level variable. (Closures can also be created with it... But that's the same idea [in this situation].)

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

Comments

4

function($) is an anonymous function that receives the jQuery object as it's sole parameter (of course, you would expect it to be followed by an implementation within {} blocks).

2 Comments

$ is a shortcut in many other JavaScript frameworks as well. In this case, it's simply a method parameter. Doesn't necessarily refer to a framework at all.
True, although $ is most commonly used for jQuery (and the OP mentions jQuery in his post)
2

It's an anonymous function that takes a single parameter named $.

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.