Home > Web Front-end > JS Tutorial > body text

What is the difference between jquery and js? Introduction to the usage differences between js and jquery

不言
Release: 2018-09-29 10:16:12
Original
10513 people have browsed it

We will definitely be exposed to jquery when learning js. So, what is the difference between js and jquery? This article will share with you the differences and comparisons between jquery and js. Friends in need can refer to it. I hope it can help you.

After-sales line Let’s take a brief look at the concepts of jquery and js.

js is a scripting language that is often used for web client programming, so that web pages can achieve more dynamic functions and show richer visual effects in the client browser.

jquery is a fast and concise JavaScript framework that greatly simplifies JavaScript programming.

The above is just a brief introduction to js and jquery. If you want to know more about js and jquery, you can refer to What does javascript mean? What is the use of javascript? Introduction to and Jquery and their Detailed usage.

After reading the introduction to jquery and js, let’s continue to look at the usage differences between js and jquery.

1. The most intuitive difference between jquery and js is that jQuery objects have more "$()" than js objects in appearance.

2. The difference between jquery and js operation content

Non-form elements (if it is text, use the text method, if it is html code, use the html method)

Example:

div.text();无参数的情况下是取值
div.text("aaaa");有参数的情况下是赋值
div.html();无参数的情况下是取值
div.html("aaaa");有参数的情况下是赋值
Copy after login

Form element

JS:

div.value;Value;

div.value = xxx;Assignment

JUQERY:

div.val();Without parameters, it is a value, and with parameters, it is an assignment.

3. The difference between jquery and js operating attributes

The method used to operate attributes in JS is

div.setAttribute(""," ");——Set attributes and modify attributes

div.removeAttribute("");——Remove attributes and write an attribute name in quotation marks

div.getAttribute();—— Get attributes

Methods used to operate attributes in JQUERY

Add attributes: div.attr("test","aa");——Add parameters to this attr method, and the attribute name is test, the value of the attribute is aa.

Remove attributes: div.removeAttr("test");——Remove the test attribute.

Get attributes: div.attr("test"); - Just write the name of an attribute directly in the attr method.

4. The difference between jquery and js operation styles

The keyword for operation style in JS is style.

Example:

div.style.backgroundColor= "red";
Copy after login

Set the background color of this div to red.

The keyword for operating styles in JQUERY is css.

Example:

div.css("background-color","yellow");
Copy after login

Change the background color of this div to yellow. All the styles in the CSS here are exactly the same as the styles in the css style sheet without any changes.

Note:

The JS method of operating styles can only obtain inline styles, not embedded or external ones.

JQUERY's method of operating styles can be inline or embedded.

Finally, this article ends here. For more exciting content, you can pay attention to the php Chinese website.

The above is the detailed content of What is the difference between jquery and js? Introduction to the usage differences between js and jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:在学习js的时候我们肯定能够接触到jquery,那么,js与jquery之间有什么区别呢?本篇文章将给大家来分享关于jquery与js之间的区别比较,有需要的小
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template