Home  >  Article  >  Web Front-end  >  What is the difference between JavaScript and jQuery

What is the difference between JavaScript and jQuery

清浅
清浅Original
2018-11-15 17:38:2518248browse

Difference: 1. JavaScript is a scripting language, and jQuery is a js library. 2. There are too few and complicated methods to find elements in JS; there are many ways to find elements in jQ and they are very flexible. 3. JS mainly changes the style by setting style; jQ uses css() to change the style.

What is the difference between JavaScript and jQuery

The operating environment of this tutorial: windows7 system, javascript1.8.5&&jquery1.10.0 version, Dell G3 computer.

JavaScript and jQuery are the knowledge we have when learning the front-end, so do you know the difference between the two? I will share it with you in the article

JavaScript

JavaScript is a small, lightweight cross-platform scripting language and an object-oriented programming language that can run program code through a browser.

It has many advantages, such as data verification on the client side, which can reduce network transmission, and various page objects can be conveniently used for layout, appearance, background, and operation mode. It can be customized according to the user's needs. Create different pages for different needs

jQuery

jQuery is actually a js library that writes some commonly used methods into a separate js file. When using Just reference this js file directly, but it is simpler than using JavaScript.

The difference between JavaScript and jQuery

(1) There are too few and complicated methods to find elements in JavaScript, but there are many ways to find elements in jQuery Various and very flexible

(2) JavaScript reuses a large number of for loops when traversing arrays, and jQuery has an implicit iteration feature so there is no need to write a for loop by hand.

(3) JavaScript has various browser compatibility issues, and the code is complex and redundant, but jQuery has no compatibility issues at all.

(4) Implementing simple animation effects in JavaScript is very complex and requires a large amount of code, while implementing animation in jQuery is very simple and more powerful

(5) Differences in entry functions

The entry function in JavaScript will not start execution until all resources (including images and files) in the page are loaded. In the entry function of .jQuery

[Recommended learning: javascript advanced tutorial]

will only wait for the document tree to be loaded before starting execution, and will not wait for the image , file loading.

(6) The difference between getting elements

JavaScript gets a DOM object

var demo=document.getElementById("demo");

jQuery gets a jQuery object

var demo=$("#demo")

( 7) Differences in attribute operations

The following methods are used to operate in JavaScript

setAttribute();设置属性、修改属性
getAttribute();获取属性
removeAttribute();移除属性

The method of operating attributes in jQuery is

attr("属性名","值"):添加属性,传递两个参数时表示给这个方法加入一个参数
attr(""):获取属性,传一个参数表获取值
removeAttr(""):移除属性

(8) Different operation styles

In JavaScript, style is mainly set to change the style.

<div style="backgroundColor="pink""></div>//设置背景颜色

jQuery uses css to set it

$("div").css("background-color","yellow")//设置背景颜色

Summary: The above is the difference between JavaScript and jQuery, and there are other differences. Everyone is welcome to add.

Recommended related tutorials: jQuery Tutorial (Video)

The above is the detailed content of What is the difference between JavaScript and jQuery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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