1, eq() Filter out the element with the specified index number
2, first() Filter out the first matching element
3, last() Filter out the last matching element
4, hasClass() Check whether the matching element Contains the specified class
5, filter() Filter out the set of elements that match the specified expression
6, is() Check whether the element can match the parameter
7, map()
8, has() Filter out the set containing Specify the elements of the child element
9, not() Exclude elements that can be matched in the parameters
10, slice() Starting from the specified index, intercept the specified number of elements
11, children() Filter to obtain the resources of the specified element
12 , closest() Starting from the current element, return the first matching parent element that meets the conditions
13. find() Find the child element from the specified element
14. next() Get the next sibling element of the specified element
15. nextAll() Get all subsequent sibling elements
16, nextUntil() Get the subsequent elements until the parameters can match, excluding the end condition
17, offsetPosition() Return the first ancestor used for positioning Element, that is, find the element whose position is relative or absolute among the ancestor elements.
18. parent() Get the direct parent element of the specified element
19. parents() Get all the ancestor elements of the specified element, all the way to
20. parentsUntil() Get the ancestor elements of the specified element , until the parameters can be matched
21. prev() Get the previous sibling element of the specified element
22. prevAll() Get all the sibling elements before the specified element
23. prevUntil() Get all the brothers before the specified element elements until the conditions in the parameters can be matched. Note that the parameter condition itself will not be matched
24. siblings() Get the sibling elements of the specified element, regardless of before or after
25. add() Add the selected element to the jQuery object collection
26. andSelf() Add itself to In the selected jQuery collection, to facilitate one-time operations
27. end() Will roll back the operation that changes the selection of the current selector to the previous state.
28, contents Not understood
****************************** Filter****************** **********************
1. eq() Filter the elements with the specified index number
Syntax: eq(index|-index) The index number starts from 0, If it is a negative value, count down from the last one, and the last one starts from -1
$("p").eq(1); //如果選擇器改為 $("p").eq(-1),則我是第四個(gè)P會(huì)被選中 <div> <p>我是第一個(gè)P</p> <p>我是第二個(gè)P</p> //會(huì)被選中,索引值為1 <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> </div>
2. first() Filter out the first matching element
Syntax: first() This method No parameters
$("p").first(); <div> <p>我是第一個(gè)P</p> //我的索引值是0,我是第一個(gè),我會(huì)被選中 <p>我是第二個(gè)P</p> <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> </div>
3. last() Filter out the last matching element
Syntax: last() This method has no parameters
$("p").last(); <div> <p>我是第一個(gè)P</p> <p>我是第二個(gè)P</p> <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> //我是最后一個(gè),我會(huì)被選中 </div>
4. hasClass() Check whether the matching element contains Specified class
Syntax: hasClass(class) Class is the category name //returns a Boolean value
if($("p").hasClass("p2")) { alert("我里面含有class=p2的元素"); //會(huì)彈出,p里的確存在class="p2"的元素 } <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> </div>
5. filter() Filter out the set of elements that match the specified expression
Syntax: filter (expr|obj|ele|fn) expr: matching expression | obj: jQuery object, used to match existing elements | DOM: DOM element used for matching | function return value as matching condition
$("p").filter(".p2"); <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> //我會(huì)被選中,我的class="p2" <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> </div>
6. is() Check whether the element can be matched in the parameters
Syntax: is(expr|obj|ele|fn) expr: matching expression | obj: jQuery object, used to match existing elements | DOM: DOM element used for matching | function return value as matching condition
$($("p").first().is(".p2")) { alert("不會(huì)彈出,因?yàn)榈谝粋€(gè)P的class不等于p2"); } <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> //我會(huì)被選中,我的class="p2" <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> </div>
7. map()
8. has() Filter out the elements containing the specified sub-element
Syntax: has(expr|ele) expr: selection expression | DOM element selection
$("div").has("p"); <div> //本div會(huì)被選中,因?yàn)樵揹iv含有p子元素 <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> <p>我是第三個(gè)P</p> <p>我是第四個(gè)P</p> </div> <div> <span>我是一個(gè)span</spam> </div>
9. not() Exclude elements that can be matched in the parameters
Syntax: not(expr|ele|fn) expr: selection expression | DOM element selection | The function of fn is not clear yet
$("p").not(".p2"); <div> <p>我是第一個(gè)P</p> //會(huì)被選中,沒有class=p2 <p class="p2">我是第二個(gè)P</p> //不會(huì)被選中,因?yàn)橛衏lass=p2被not(".p2")排除了 <p>我是第三個(gè)P</p> //會(huì)被選中,沒有class=p2 <p>我是第四個(gè)P</p> //會(huì)被選中,沒有class=p2 </div>
10. slice() Starting from the specified index, intercept the specified number of elements
Syntax: slice(start, [end]) Start position, end can Select the end position, excluding the end position. If not specified, the last one is matched.
$("p").slice(1,3) <div> <p>我是第一個(gè)P</p> //不會(huì)被選中,我索引為0 <p class="p2">我是第二個(gè)P</p> //會(huì)被選中,我索引為1 <p>我是第三個(gè)P</p> //會(huì)被選中,我索引為2 <p>我是第四個(gè)P</p> //不會(huì)被選中,雖然我的索引為3,但是不包括我 </div>
************************ Filter************************ *************
11. children() Filter to obtain the resources of the specified element
Syntax: children(expr); Get the resources of the specified element, expr is the filtering condition for the child element
$("div").children(".p2"); <div> <p>我是第一個(gè)P</p> //不會(huì)被選中,雖然我是div的子元素,但是我沒class=p2 <p class="p2">我是第二個(gè)P</p> //會(huì)被選中,我既是p的子元素,又有class=p2 <p>我是第三個(gè)P</p> //不會(huì)被選中,雖然我是div的子元素,但是我沒class=p2 <p>我是第四個(gè)P</p> //不會(huì)被選中,雖然我是div的子元素,但是我沒class=p2 </div>
12. closest() Starting from the current element, return the first matching parent element that meets the conditions
$("span").closest("p","div"); <div> //不會(huì)被選中,被P搶了先機(jī) <p>我是第一個(gè)P //P會(huì)被選中,因?yàn)镻符合條件,而且是最先匹配到的,雖然div也符合條件了,但是div不是最先匹配到的。因此div不會(huì)被選中。 <span>我是P里的span</span> </p> </div>
13. find() Find child elements from the specified element
Syntax: find(expr|obj|ele) expr: matching expression | obj jQuery object used for matching | DOM element
$("div").find(".p2"); <div> <p>我是第一個(gè)P</p> //不會(huì)被選中,雖然我是div的子元素,但是我沒class=p2 <p class="p2">我是第二個(gè)P</p> //會(huì)被選中,我既是p的子元素,又有class=p2 <p>我是第三個(gè)P</p> //不會(huì)被選中,雖然我是div的子元素,但是我沒class=p2 <p>我是第四個(gè)P</p> //不會(huì)被選中,雖然我是div的子元素,但是我沒class=p2 </div>
十四、next() 獲取指定元素的下一個(gè)兄弟元素
語(yǔ)法:next(expr) expr:可選,篩選條件,如果下一個(gè)兄弟元素不符合改條件,則返回空。
$(".p2").next(); //如果篩選改為$(".p2").next(".p4")那選中的是哪個(gè)呢?答案是:沒選中任何元素,因?yàn)殡m然有個(gè)class=p4的P,但它不是.p2的下一個(gè)?! ? <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> <p>我是第三個(gè)P</p> //我是.p2的next <p class="p4">我是第四個(gè)P</p> </div>
十五、nextAll() 獲取其后的所有兄弟元素
語(yǔ)法:nextAll(expr) expr:可選,篩選條件,獲取其后符合expr條件的所有兄弟元素
$(".p2").nextAll(); //如果篩選條件改為 $(".p2").nextAll(".p4"); 則只有我是第四個(gè)P會(huì)被選中 <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> <p>我是第三個(gè)P</p> //會(huì)被選中,是.p2后面的兄弟元素 <p class="p4">我是第四個(gè)P</p> //會(huì)被選中,是.p2后面的兄弟元素 </div>
十六、nextUntil() 獲取其后的元素,直到參數(shù)能匹配上的為止,不包括結(jié)束條件那個(gè)
語(yǔ)法:nextUntil([expr|ele][,fil]) expr篩選表達(dá)式 | DOM元素篩選,注意不包括參數(shù)里的那一個(gè)
$(".p2").nextUntil(".p4"); //注意此方法并不會(huì)包括.p4 <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> <p>我是第三個(gè)P</p> //會(huì)被選中,是.p2后面的兄弟元素 <p class="p4">我是第四個(gè)P</p> //不會(huì)被選中,我作為結(jié)束條件,但不包括我 </div>
十七、offsetPosition() 返回第一個(gè)用于定位的祖先元素,即查找祖先元素中position為relative或absolute的元素。
語(yǔ)法:offsetPosition() 此方法沒有參數(shù) 由于CSS的絕對(duì)定位的定位基準(zhǔn)是相對(duì)最近的一個(gè)已定位元素,因此此方法的作用不言而喻。
$("span").offsetParent(); <div style="position:relative"> //選中的是div,因此div是已定位元素。 <p> <span>我是一個(gè)span</span> </p> </div>
十八、parent() 獲取指定元素的直接父元素
語(yǔ)法:parent(expr) expr為篩選條件,如果直接父元素不符合條件,則不返回任何元素(無論它的祖先是否具有能與expr匹配的)
$("span").parent(); <div style="position:relative"> <p> //我是span的直接父元素,我會(huì)被匹配到 <span>我是一個(gè)span</span> </p> </div>
十九、parents() 獲取指定元素的所有祖先元素,一直到
語(yǔ)法:parents(expr) expr為篩選條件,如果某個(gè)祖先元素不符合expr則排除
$("span").parents(); <div style="position:relative"> //我是span的祖先元素,我也會(huì)被匹配到.另外<body></body>也會(huì)被匹配到 <p> //我是span的直接父元素,我會(huì)被匹配到 <span>我是一個(gè)span</span> </p> </div>
二十、parentsUntil() 獲取指定元素的祖先元素,知道參數(shù)里能匹配到的為止
語(yǔ)法:parentsUntil(expr) expr為停止參數(shù),一直匹配到expr為止,同時(shí)參數(shù)的條件是不會(huì)被匹配中的。
$("span").parentsUntil("div"); <div style="position:relative"> //我是span的祖先元素,但是我作為停止條件,我也不會(huì)被選中 <p> //我是span的直接父元素,我會(huì)被選中 <span>我是一個(gè)span</span> </p> </div>
二十一、prev() 獲取指定元素的前一個(gè)兄弟元素
語(yǔ)法:prev(expr) expr:可選。當(dāng)上一個(gè)兄弟元素不符合參數(shù)中的條件時(shí),不返回任何元素。
$(".p2").prev(); <div> <p>我是第一個(gè)P</p> //我會(huì)被選中,我是.p2的前一個(gè)元素。 <p class="p2">我是第二個(gè)P</p> <p>我是第三個(gè)P</p> <p class="p4">我是第四個(gè)P</p> </div>
二十二、prevAll() 獲取指定元素前面的所有兄弟元素
語(yǔ)法:prevAll(expr) expr:可選,排除所有不能夠被expr匹配上的元素
$(".p4").prevAll(".p2"); <div> <p>我是第一個(gè)P</p> //不會(huì)被選中,雖然我是.p4前面的兄弟元素,但是我沒有class=p2 <p class="p2">我是第二個(gè)P</p> //會(huì)被選中,我既是.p4前面的兄弟元素,而且我有class=p2 <p>我是第三個(gè)P</p> //不會(huì)被選中,雖然我是.p4前面的兄弟元素,但是我沒有class=p2 <p class="p4">我是第四個(gè)P</p> </div>
二十三、prevUntil() 獲取指定元素前面的所有兄弟元素,直到參數(shù)里的條件能夠匹配到的。 注意參數(shù)條件本身不會(huì)被匹配
語(yǔ)法:prevUntil([expr|ele][,fil]) expr匹配表達(dá)式 | DOM元素匹配
$(".p4").prevUntil(".p2"); <div> <p>我是第一個(gè)P</p> //不會(huì)被選中,到p2就停止了 <p class="p2">我是第二個(gè)P</p> //不會(huì)被選中,我是停止條件,不包括我 <p>我是第三個(gè)P</p> //會(huì)被選中,我在.p2前,遞歸到我在到.p2 <p class="p4">我是第四個(gè)P</p> //不會(huì)被選中,我自己怎么可能是我自己前面的呢? </div>
/******************** 串聯(lián) *******************************/
二十四、siblings() 獲取指定元素的兄弟元素,不分前后
語(yǔ)法:siblings(expr); expr為篩選條件,不符合條件的不會(huì)選中
$(".p2").siblings(); <div> <p>我是第一個(gè)P</p> //會(huì)被選中,我是.p2的兄弟元素 <p class="p2">我是第二個(gè)P</p> //不會(huì)被選中,我是自己 <p>我是第三個(gè)P</p> //會(huì)被選中,我是.p2的兄弟元素 <p class="p4">我是第四個(gè)P</p> //會(huì)被選中,我是.p2的兄弟元素 </div>
二十五、add() 將選中的元素添加到j(luò)Query對(duì)象集合中
add(expr|elements|html|jQueryObject) expr:選擇器表達(dá)式 | DOM表達(dá)式 | Html片段 | jQuery對(duì)象,將jQuery對(duì)象集合一起方便操作;
$(".p2").add("span").css("background-color","red"); <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> //會(huì)變紅 <p>我是第三個(gè)P</p> <p class="p4">我是第四個(gè)P</p> </div> <span>我是一個(gè)span</span> //會(huì)變紅
二十六、andSelf() 將自身加到選中的jQuery集合中,以方便一次性操作
andSelf() 此方法無參數(shù)
$(".p2").nextAll().andSelf().css("background-color","red"); <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> //會(huì)變紅,這就是andSelf()的效果 <p>我是第三個(gè)P</p> //會(huì)變紅 <p class="p4">我是第四個(gè)P</p> //會(huì)變紅 </div>
二十七、end() 將改變當(dāng)前選擇器選中的操作回退為上一個(gè)狀態(tài)。
end() 此方法沒有參數(shù)
$(".p2").next().end().css("background-color","red"); <div> <p>我是第一個(gè)P</p> <p class="p2">我是第二個(gè)P</p> //會(huì)變紅,這就end()的效果 <p>我是第三個(gè)P</p> //不會(huì)變紅,盡管next()方法之后選中的是這一個(gè),但是由于被end()方法回退了因此是上一個(gè)。 <p class="p4">我是第四個(gè)P</p> </div>
? ?

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

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

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:
