Is jquery javascript?
jquery is not javascript. JavaScript is an interpretive scripting language, and jquery is a JavaScript function library, a framework written based on the JavaScript language; and there are many differences in syntax between the two.
The operating environment of this tutorial: windows7 system, javascript1.8.5&&jquery1.10.2 version, Dell G3 computer.
jquery is not javascript.
javascript is an interpretive scripting language, and jquery is a JavaScript function library, a framework written based on JavaScript language
To use JQuery, you must first put it at the front of the HTML code Add a reference to the jQuery library, for example:
<script src="js/jquery.min.js"></script>
The library file can be placed locally, or you can directly use the CDN of a well-known company. The advantage is that the CDN of these large companies is more popular, and users will not be able to access your website for a long time. It may have been cached in the browser when visiting other websites, so it can speed up the opening of the website. Another benefit is obvious, saving website traffic bandwidth. For example:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> //Google 或者: <script src="http://code.jquery.com/jquery-1.6.min.js"></script> //jQuery 官方
There are many differences in syntax between jquery and javascript
1. Manipulate element nodes
a. JavaScript uses
getElement series, query series
<body> <ul> <li id="first">哈哈</li> <li class="cls" name ="na">啦啦</li> <li class="cls">呵呵</li> <li name ="na">嘿嘿</li> </ul> <div id="div"> <ul> <li class="cls">呵呵</li> <li>嘿嘿</li> </ul> </div> </body> <script> document.getElementById("first"); //是一个元素 document.getElementsByClassName("cls"); //是一个数组,即使只有一个元素,使用时需要用[0]取到第一个再使用 document.getElementsByName("na"); //是一个数组,即使只有一个元素,使用时需要用[0]取到第一个再使用 document.getElementsByTagName("li"); //是一个数组,即使只有一个元素,使用时需要用[0]取到第一个再使用 document.querySelector("#div"); //是一个元素 document.querySelectorAll("#div li"); //是一个数组,即使只有一个元素,使用时需要用[0]取到第一个再使用 </script>
b.JQuery uses
A large number of selectors and uses $() to wrap the selector
<body> <ul> <li id="first">哈哈</li> <li class="cls" name ="na">啦啦</li> <li class="cls">呵呵</li> <li name ="na">嘿嘿</li> </ul> <div id="div"> <ul> <li class="cls">呵呵</li> <li>嘿嘿</li> </ul> </div> </body> <script src="http://code.jquery.com/jquery-1.6.min.js"></script> <script> //使用JQuery取到的是jquery对象都是一个数组,即使只有一个元素被选中,但是在使用时候不一定需要使用:eq(0)来拿到这一个在使用可以直接使用 $("#first"); $(".cls"); $("li type[name='na']"); $("li"); $("#div"); $("#div li"); </script>
2. Manipulate attribute nodes
##a.JavaScript uses getAttribute("Attribute name"), setAttribute("Attribute name","Attribute value ")<body> <ul> <li id=>哈哈</li> </ul> </body> <script>).getAttribute().setAttribute(, document.getElementById("first").removeAttribute("name"); </script>
<body> <ul> <li id="first">哈哈</li> </ul> </body> <script src="js/jquery.js"></script> <script> $("#first").attr("id"); $("#first").attr("name","nafirst"); $("#first").removeAttr("name"); $("#first").prop("id"); $("#first").prop("name","nafirst"); $("#first").removeProp("name"); </script>
3. Operation text node
a.JavaScript usage innerHTML: Get or set the HTML code of a node, you can get the css and return it in the form of text innerText: Get or set the HTML code of a node HTML code, cannot get cssvalue: Get the text entered by input[type='text']<body> <ul> <li id="serven_times" ><span style="color: chartreuse">嘿嘿</span></li> <li id="eight_times" ><span style="color: chartreuse">嘿嘿</span> </li> </ul> 姓名:<input type="text" id="input"> </body> <script> document.getElementById("serven_times").innerHTML; document.getElementById("serven_times").innerHTML = "<span style='color: #ff3a29'>呵呵</span>"; document.getElementById("eight_times").innerText; document.getElementById("eight_times").innerText = "啦啦"; document.getElementById("input").value; </script>
.text() Get or set the text in the node
.val() Get or set the value attribute value of the input
<body> <ul> <li id="serven_times" ><span style="color: chartreuse">嘿嘿</span></li> <li id="eight_times" ><span style="color: chartreuse">嘿嘿</span> </li> </ul> 姓名:<input type="text" id="input"> </body> <script src="/js/jquery.min.js"></script> <script> $("#serven_times").html(); $("#serven_times").html("<span style='color: #ff3a29'>呵呵</span>"); $("#eight_times").text(); $("#eight_times").text("啦啦"); $("#input").val(); $("#input").val("哈哈"); </script>
4. When operating css styles
JavaScript:1. Use setAttribute to set class and styledocument.getElementById("first").setAttribute("style","color:red");
document.getElementById("third").className = "san";
document.getElementById("four_times").style.fontWeight = "900";
document.getElementById("five_times").style = "color: blue;";//IE不兼容 document.getElementById("six_times").style.cssText = "color: yellow;font-size : 60px;";
$("#p2").css("color","yellow"); $("#p2").css({ "color" : "white", "font-weight" : "bold", "font-size" : "50px", });
*1.childNodes:获取当前节点的所有子节点(包括元素节点和文本节点) * children:获取当前节点的所有元素子节点(不包括文本节点) *2.parentNode:获取当前节点的父节点 *3.firstChild:获取第一个元素节点,包括回车等文本节点 * firstElementChild:获取第一个元素节点,不包括回车节点 * lastChild、lastElementChild 同理 *4.previousSibling:获取当前元素的前一个兄弟节点 * previousElementSibling::获取当前元素的前一个兄弟节点 * nextSibling、nextElementSibling
- :first-child
- :first-of-type1.9
- :last-child
- :last-of-type1.9
- :nth-child
- :nth-last-child ()1.9
- :nth-last-of-type()1.9
- :nth-of-type()1.9
- :only-child
- :only-of-type
- first()
- last()
- children( )
- parents()
- parent()
- siblings()
6. Bind an event to a node
JavaScript: Using Dom0 event model and Dom2 event Model, please see my last blog for detailsJQuery: ①.Shortcut for event binding
<body> <button>按钮</button> </body> <script src="js/jquery-1.10.2.js"></script> <script> $("button:eq(0)").click(function () { alert(123); }); </script>
on for event binding
<body> <button>按钮</button> </body> <script src="js/jquery-1.10.2.js"></script> <script> //①使用on进行单事件的绑定 $("button:eq(0)").on("click",function () { alert(456); }); //②使用on同时给同一对象绑定多个事件 $("button:eq(0)").on("click dblclick mouseover",function () { console.log(123); }); //③使用on,给一个对象绑定多个事件 $("button:eq(0)").on({ "click":function () { console.log("click"); }, "mouseover":function () { console.log("mouseover"); }, "mouseover":function () { console.log("mouseover2"); } }); //④使用on给回调函数传参,要求是对象格式,传递的参数可以在e.data中取到;jquery中的e只能通过参数传进去,不能用window.event $("button:eq(0)").on("click",{"name":"zhangsan","age":15},function (e) { console.log(e); console.log(e.data); console.log(e.data.name); console.log(e.data.age); console.log(window.event);//js中的事件因子 }); </script>
The above is the detailed content of Is jquery javascript?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:
