search
HomeWeb Front-endJS TutorialUnderstand the differences between jQuery, JavaScript, and JS in two minutes

Understand the differences between jQuery, JavaScript, and JS in two minutes

##Two minutes to understand the difference between jQuery, JavaScript, and JS

JavaScript , jQuery, and JS often appear in our lives. Do you know what are the similarities and differences between them? Let’s take two minutes to learn about them below.

JavaScript: It is a common scripting language in browsers, which is used to realize the dynamics of web pages and the interaction with the back-end (database). jQuery: It is a class library integrated with JavaScript. By operating jQuery, you can reduce the use of native JavaScript statements, thereby improving efficiency.
JS: It is an abbreviation of JavaScript.

Summary of differences:
1. JQuery greatly simplifies JavaScript and accomplishes the arduous task of completing more functions with the least code to the greatest extent.
2. JavaScript loads the DOM only once, while JQuery loads it multiple times.
3. JQuery is more convenient to operate DOM. Such as node acquisition. Eg: $()

Description: The most direct way to improve the understanding of native JavaScript and encapsulated JQuery is to achieve basic front-end and back-end interaction without introducing JQuery into the page.

The following content is a summary compiled to understand jQuery and JS differently:



jQuery- and native Javascript writing method:
1 Positioning elements

JS:

document.getElementById("abc")

jQuery:


$("#abc") 通过id定位 
$(".abc") 通过class定位 
$("p") 通过标签定位

Note: The result returned by JS is this element, and the result returned by jQuery is a JS object . The following example assumes that element abc has been positioned.


2 Change the content of the element
JS:

abc.innerHTML = "test";                //现在的项目中有用到

jQuery:


abc.html("test");

3 Show hidden elements JS:

abc.style.display = "none";              //现在的项目中有用到
abc.style.display = "block";

jQuery:


abc.hide(); 
abc.show();
abc.toggle();         //在显示和隐藏之间切换、

4 Get focus JS and jQuery are The same, abc.focus();

5 Assign values ​​to the form JS:

abc.value = "test";

jQuery:


abc.val("test");

6 Get the value of the form
JS:

alert(abc.value);

jQuery:


alert(abc.val());

7 Setting the element is not available JS:

abc.disabled = true;

jQuery:


abc.attr("disabled", true);

8 Modify element style JS:

abc.style.fontSize=size;

jQuery:


abc.css('font-size', 20);

JS:


abc.className="test";

JQuery:


abc.removeClass(); 
abc.addClass("test");

9 Determine whether the check box is selected jQuery

if(abc.attr("checked") == "checked")

Note: It is said on the Internet that .attr("checked") == true cannot actually be used, but the above one has been tested and works

The difference between JS and JQUERY

1. Get elements based on ID JS: What you get is a DOM object.
Example:

var p = document.getElementByID("one");

JQUERY: What is obtained is a JQUERY object.

Example:

var p = $("#one");

2. Get elements according to class [In the array, if you want to get the DOM object, use the index method, if you want to get the JQUERY object, use eq()] JS: What is obtained is an array
Example:

var p = document.ElementsByClassName("test");

JQUERY:

Example:

var p = $(".test");

3. Get elements based on name JS: Returns an array
Example:

var bd = document.getElementsByName(uid);

JQUERY: The method is to use square brackets, attribute = a value, there is no restriction to get the value based on the name, JQUERY takes the element based on the attribute

Example:

$("[name='uid']");

4. Get the element based on the tag name JS: The returned value is also an array
Example:

var p = document.getElementsByTagName("p");

JQUERY: And style The method of adding styles to all p in the table is the same. Write the tag name directly within double quotes

Example:

$("p");

Eg: Specify subdirectory element object acquisition: var p = $("p span") ;——There are many combination methods

Operation content

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

Example:

1.1. If there are no parameters, the value is
p.text();
p.html();
1.2. If there are parameters, they are assigned values
p.text("aaaa");
p.html("aaaa");

2. Form elements JS:
2.1. Get value
p.value;
2.2. Assign value
p.value = 'xxx';
JUQERY:
2.3. Get value
p.val() ;
3.4. Assignment
p.val('xxx');

Operation attributes

JS operation attributes
Set | Modify attributes:

p.setAttribute("","");

Delete attributes


p.removeAttribute("");

Get attributes


p.getAttribute();

Used in JQUERY Methods of operating attributes Add attributes:

p.attr("width","20%");

Remove attributes:


p.removeAttr("width");

Get attributes:


p.attr("width");

操作样式
JS操作样式-关键字是[style]
例:

p.style.backgroundColor = "red";

JQUERY里面操作样式的关键字是css
例:

p.css("background-color","yellow");

——把这个p的背景色变为黄色,在这里CSS里面所有的样式和css样式表里面的样式是一模一样的没有任何变化
JS操作样式的方法只能获取内联样式,不能取内嵌的和外部的!!!!!
JQUERY操作样式的方法可以是内联的也可以是内嵌的

感谢大家的阅读,希望大家收益多多。

本文转自:https://blog.csdn.net/dalei9243/article/details/79804789

推荐教程:《JS教程

 

The above is the detailed content of Understand the differences between jQuery, JavaScript, and JS in two minutes. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript: Exploring the Versatility of a Web LanguageJavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.