What is the meaning of symbol $ in jQuery?
The jQuery object :)
From the jQuery documentation:
By default, jQuery uses "$" as a shortcut for "jQuery"
jQuery("#id") is the same.
Q anyway). It is just an uninformative variable name.
In jQuery the variable is assigned a copy of the
jQuery function. This function is heavily overloaded and means half a dozen different things depending on what arguments it is passed. In this particular example you are passing it a string that contains a selector, so the function means "Create a jQuery object containing the element with the id Text".
How the symbol $ in jquery works?
window.jQuery = window.$ = jQuery;
Meaning that the window-scoped
$ variable will be assigned to the jQuery namespace, in which all the jQuery functions are placed under. This is why you can use
jQuery in your code as well as
You could do this easily yourself by the same method and another character symbol, even:
window.$$ = jQuery;
would mean that jQuery is now assigned to
_, digits and letters.
CoffeeScript has a few nice features related to the this keyword.
First, CoffeeScript uses the @ symbol as shorthand for this.. For
example, @foo is equivalent to this.foo. Second, if you use the @
symbol in the parameters of a function, CoffeeScript will
automatically assign those values as properties of the object.
@ in jQuery, see this question or the docs.
What do dot and hash symbols mean in JQuery?
The hash (#) specifies to select elements by their ID's
The dot (.) specifies to select elements by their classname
You can read more about the selectors here: http://api.jquery.com/category/selectors/basic-css-selectors/
There's nothing mysterious about the use of
_, and others.¹
$ as the primary base object (or function). Most of them also have a way to relinquish the
$ so that it can be used with another library that uses it. In that case you use
jQuery instead of
$. In fact,
$ is just a shortcut for
_; details in the specification. For subsequent characters in an identifier, it allows anything with
ID_Continue (which includes
$ (and a couple of control characters for historical compatibility).
Why does JQuery have dollar signs everywhere?
$ 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.)
It doesn't mean anything special.
$ as the "central" interface to them, or at least as a shortcut for accessing their functionality.
For example, if you're using jQuery and you say
$("div"), this is a call to the
$ function with argument "div". When you say
$.post(), it's calling the
post method on the
What does the '#' sign mean in jQuery?
$ function might do something with it, but it is hard to tell what the
$ function is.
There are a lot of libraries which provide a
$ function that acts as a kitchen sink for that library. They include Prototype, Mootools and jQuery. This one looks most like jQuery, in which case the argument is a string containing a CSS selector, so the
# indicates the start of an id selector.
This "Selects a single element with the given id attribute".
What's the meaning of $ in front of a variable
As everyone said, its just a convention.
I use the
$ sign in front of a variable to identify that this variable holds an object.
var thisIsANumber = 1024; // No $.. Its a normal variable
var $divElement = $('div#idOfDiv'); // Yes! Its a jQuery Object
//Now I can use something like this.. (Notice how easy it is to read!)
// Or a more `real world` example!
// Hold $(this) inside a variable
// So we don't have to traverse the dom unnecessarily
var $this = $(this); // Save it (its a object.. so prepend a `$` )
$this.hide(); // Use it again
$this.fadeIn(); // and again
// ^ Has a dollar sign, because it is a jQuery Object.
You will see loads of plugins use this convention (well.. at least the well written ones).
If you use
$(this) more then once inside the same callback function, you should store it inside a variable.. (
How to Download File from Server
Create an Instance of a Class in Es6 with a Dynamic Name
Prevent Jquery UI Dialog from Setting Focus to First Textbox
How to Access a Child's State in React
React Functional Stateless Component, Purecomponent, Component; What Are the Differences and When Should We Use What
Get Wrong Value in Data Attribute Jquery
Garbage Collection with Node.Js
Differencebetween Typeof and Instanceof and When Should One Be Used VS. the Other
Using Jquery to Find an Element at a Particular Position