Why does JQuery have dollar signs everywhere?

$ sign is an alias for jQuery. A short version of jQuery, a less write mechanism.

Just for an example: (in jQuery it's more complicated)

var yourFunction = function() {
    alert('a function');
}

window.Myf = yourFunction;

Now you can call yourFunction like:

Myf(); // definitely a short syntax

$ is just a shortcut for jQuery. The idea is that everything is done with the one global symbol (since the global namespaces is ridiculously crowded), jQuery, but you can use $ (because it's shorter) if you like:

// These are the same barring your using noConflict (more below)
var divs = $("div");       // Find all divs
var divs = jQuery("div");  // Also find all divs, because
console.log($ === jQuery); // "true"

If you don't want to use the alias, you don't have to. And if you want $ to not be an alias for jQuery, you can use noConflict and the library will restore $ to whatever it was before jQuery took it over. (Useful if you also use Prototype or MooTools.)

Tags:

Jquery