<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-12-04 15:27:51Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
I've seen $. used but I've never understood what it stands for. Example that got me thinking:
$.getJSON("url", function(result){
$.each(result, function(i, field){
$(".test").append(field + " ");
});
EDIT: Right, I'm embarrassed. I knew it referred to jQuery but I've only used jQuery for DOM manipulation, I'm so used to having elements to be worked on, it threw off guard a little. Thanks for your informative replies.
</div>
It's an alias for the jQuery object itself, so instead of having to write:
jQuery.getJSON("url", function(result){
jQuery.each(result, function(i, field){
jQuery(".test").append(field + " ");
});
you can write the more convenient code (as you have posted)
$ is an alias for jQuery - see the very top of the library for the code.
According to the JQuery documentation:
By default, jQuery uses "$" as a shortcut for "jQuery"
It's same as your full name is 'Meghananth Rahtod' and people call you Megh.
The easy case - $
and jQuery
are the same thing assigned to different variables.
$
is the main jQuery
object, which is actually a function that you can call, hence the ability to do
$(selector)
However, functions in JavaScript are objects themselves, so you can attach methods to them and call them later. So $.each
is actually a method on the $
object.
Basically $.
is not something special about jQuery, but simple method invocation.
Just an alias to the jQuery
object. Both $
and jQuery
do the same.
This is a part of jQuery source code:
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
You can access to this here: http://code.jquery.com/jquery-1.8.3.js
jQuery is open-source.
It might be confusing, but $
is a valid identifier in Javascript.
It's an alias for jQuery. The $ is a function of jQuery, but when you use $("")
, $(null
), $(undefined)
or $(false)
, the jQuery return "this", making the call to itself. In the line 100 of jQuery file (development, version 1.8.3) you can see this.
Other ways to call the jQuery: window.jQuery
, window.$
or jQuery
.
You can see more here too: http://www.hackification.com/2008/11/27/a-developers-introduction-to-jquery/