admin管理员组文章数量:1287665
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 es 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!
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 es 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!
Share Improve this question edited Jan 19, 2018 at 0:13 8protons asked Mar 1, 2016 at 19:39 8protons8protons 3,9796 gold badges34 silver badges71 bronze badges 11- 3 @8protons — There are a lot of cargo cult copy/paste web page authors out there. Many of them don't understand the difference between JavaScript and jQuery. That doesn't mean calling some JavaScript "jQuery" just because it calls the jQuery library is correct or normal though. – Quentin Commented Mar 1, 2016 at 19:45
- 2 It's a good and valid question -- sad to see it downvoted. – Cymen Commented Mar 1, 2016 at 19:48
-
2
@8protons There's no method, only madness ;) Why do people refer to them as separate things? Because they're confused. Why does jQuery use
$
? Because it's a convenient identifier that stands out. – Mike Cluck Commented Mar 1, 2016 at 19:49 - 2 @8protons — jQuery is jQuery, other things many use it or be plugins for it. jQuery. has a searchable database of plugins, but they are plugins and have their own names and just depend on jQuery without being part of it. – Quentin Commented Mar 1, 2016 at 19:50
- 2 @8protons You got it! That's all there is to it. – Mike Cluck Commented Mar 1, 2016 at 19:54
4 Answers
Reset to default 10JavaScript 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.
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.
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.
$()
is valid JavaScript grammar. jQuery is a library and has defined the function$
. In JavaScript you call a function with ()
.
本文标签: Is ( ) JavaScript or jQuery notationStack Overflow
版权声明:本文标题:Is $( ) JavaScript or jQuery notation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741308013a2371484.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论