Reputation: 3959
I'm trying to differentiate between the JavaScript and jQuery; to sculpt accurate models of what the two represent.
Originally, I had thought that jQuery was a collection of libraries, plug-ins, and tool kits. I came to this notion due to what a peer told me, from reading around on the Internet, and also because I've been using Slick (an image carousel) which I downloaded from jQuery.
Yet as I've been developing more and getting to know JavaScript, instead of doing specific calls to a library I downloaded (Slick):
$('.multiple-items').slick({...});
I've lately been doing calls like the following:
$('.mid-buttons').click(function(){...});
Which confuses me, because I never downloaded any jQuery library other than Slick, so is .click part of some automatically downloaded jQuery library or part of what comes with JavaScript?
Also, is $() used for any calls to an object in HTML/CSS or is the methods being called, .slick or .click, what dictates the usage of $( )?
I know that these are extremely amateur questions but it's been tough finding a resource that explicetely differentiates the distinction I am trying to make/understand. Thanks!
Upvotes: 4
Views: 3400
Reputation: 943579
JavaScript is a programming language.
jQuery is a library written in JavaScript.
$
is a valid identifier name in JavaScript.
jQuery uses $
as the variable name for its main function (it also uses jQuery
). This function is defined in the jQuery documentation.
When you call it as a function (generally with the syntax $(some arguments here)
), the return value is a jQuery object. These usually wrap some DOM nodes.
Slick is a plugin. It is another library that expands the functionality of jQuery (using the jQuery plugins api). It provides a method that you can call on jQuery objects.
Upvotes: 10
Reputation: 14419
jQuery is typically exposed as both $
and jQuery
. You can run see that they are the same by running $.fn.jquery
and jQuery.fn.jquery
which will give you the version. Or run $ == jQuery
. So even though $
looks special, it's just a function like any other and by putting ()
after $
you are running the jQuery function.
Things like click
are part of the core jQuery. It has a monolithic approach to plugins in that they augment the jQuery instance variable ($
or jQuery
). If you try CommonJS, you'll see a non-monolithic approach to how different pieces of JavaScript code can be pulled together.
Upvotes: 1
Reputation: 32511
jQuery is a library. It's got it's own set of functionality. What you downloaded was a jQuery plugin, i.e., it extends jQuery.
jQuery itself is just Javascript. Nothing more, nothing less. You can even read an annotated version of the source code here.
$()
is the jQuery function. It's the basic starting point for most things in jQuery. In it's simplest form, it's a way of grabbing DOM nodes and wrapping them in a special wrapper which has access to the rest of the jQuery API.
Upvotes: 1
Reputation: 14649
$()
is valid JavaScript grammar. jQuery is a library and has defined the function$
. In JavaScript you call a function with ()
.
Upvotes: 0