Home Web Front-end JS Tutorial Learn Jquery with JQuery API Part 3 Filtering_jquery

Learn Jquery with JQuery API Part 3 Filtering_jquery

May 16, 2016 pm 06:29 PM
jquery filter

1. Filter
eq (index) Look at this function and the basic one: eq seems to be the same (actually it is the same)
For example, we have
1
1
to select, then we can use $(“div”).eq(1) or $(“div:eq(1)”)
to select the second div, the effect is the same

hasClass(class) is used to determine whether the current element contains a class. This is the same as is(“.” class). Let’s take a look at what the is() function is used for. It uses an expression. To check the currently selected set of elements and return true if at least one element matches the given expression. The parameters in is(expr) are the parameters of the selector.

filter(expr) is used to select a set of elements with matching expressions. This is somewhat similar to is, except that is is the returned bool type and is used for judgment. filter is used to narrow the range. filter The parameter in can be a function, and the return value of the function is of bool type. When the return value is true, the node is retained. In fact, it is to make a loop through the objects and then delete the unnecessary ones. For example, if there is

asdf

2343

we choose the one with class aa and change his text into a paragraph of text
$("p").filter(function() { return $( this).hasClass("aa") }).text("selected thing")

not(txpr) is used to delete matching elements. This is the same as the previous one: not()
slice(start,[end]) selects a segment starting from start to end and ending if there is no end
$("p").slice(0, 1), I always feel that the second part of this function It would be better if the variable should be num. From which one to start, select the first num.

2 Search
add(expr) Add the object that matches the expression to the original object. This is a bit like a multi-selector such as $("#id,.cs" )
It can also be written as $("#id").add(".cs") with the same effect
Children([expr]) gets the set of all child elements
Contents() finds all matching elements child nodes. If it is an iframe, search the content of the document. This can be easily used to change the content inside the iframe, such as a text editor. .
find(expr) searches for content that matches the specified expression. This can also be implemented using a selector. For example, $("ul li") can be written as $("ul").find("li")
next(expr) searches for the element immediately following among the sibling elements. This is the selector form of a b. For example, if we want to select $("div p") followed by a div followed by a p tag, of course we can also use $("div") .next("p")
nextAll() searches for all subsequent sibling elements. This is the same as a~b. $("div~p") and $("div").nextAll("p") are The same
Prev([expr]) gets the previous element of the immediately adjacent sibling element, which is exactly the opposite of next()
PrevAll([expr]) gets all the previous elements, which is exactly the opposite of nextAll()
Siblings([expr]) This function should be the sum of nextAll() and prevAll()

offsetParent() returns the parent node of the first element. Why is it the first element? This is done with JavaScript The implementation is Parent(), but we use jquery and operate jquery objects. Many tutorials emphasize that we need to distinguish between JQuery objects and JS objects. In fact, the Jquery object is an array array, which requires us to pay attention to the operation. When you want to take out the value of the array, you want to use the first and last price index [0] to get the first object.
Parent(expr) gets the parent element contained by all elements. We already know that the jquery object is an array, so it may contain multiple nodes. Then we need to find the common parent node of these multiple nodes, and It is to find a node that can contain them all. Just like there are two people, one is from Hubei and the other is from Henan. You want to find his superior, that is, they are both from China. Of course, you can also fill in a parameter parent (Hubei), then the final node we get is Hubei.

3 Concatenation
There are only two functions in concatenation andSelf() and end()
andSelf() adds the previously selected element to the current element, this explanation It's a bit convoluted to read. Here we should mention Jquery’s chain operation. For example, if you select China-Hubei, you will get the Hubei node, and then you use andSelf() to add China. This will be very useful if you want to operate on elements that you have not filtered before.
end() goes back to the last "destructive" operation. So what is destructive? It is to perform the next operation on a collection
For example, next() we mentioned earlier, here we go. We now know why the operation we can complete with $("div p") must be written as $("div").next("p").
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

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1264
29
C# Tutorial
1237
24
How to filter more than 3 keywords at the same time in excel How to filter more than 3 keywords at the same time in excel Mar 21, 2024 pm 03:16 PM

Excel is often used to process data in daily office work, and it is often necessary to use the "filter" function. When we choose to perform "filtering" in Excel, we can only filter up to two conditions for the same column. So, do you know how to filter more than 3 keywords at the same time in Excel? Next, let me demonstrate it to you. The first method is to gradually add the conditions to the filter. If you want to filter out three qualifying details at the same time, you first need to filter out one of them step by step. At the beginning, you can first filter out employees with the surname "Wang" based on the conditions. Then click [OK], and then check [Add current selection to filter] in the filter results. The steps are as follows. Similarly, perform filtering separately again

What should I do if there is data in the Excel table but the blanks are filtered? What should I do if there is data in the Excel table but the blanks are filtered? Mar 13, 2024 pm 06:38 PM

Excel is a frequently used office software. Many users record various data in the table, but the table clearly contains data and is blank when filtering. Regarding this problem, many users don’t know how to solve it. It doesn’t matter. , the content of this software tutorial is to provide answers to the majority of users. Users in need are welcome to check out the solutions. What should I do if there is data in the Excel table but the blanks are filtered? The first reason is that the table contains blank rows. We want to filter all people with the surname "Li", but we can see that the correct results are not filtered out because the table contains blank rows. How to deal with this situation? Solution: Step 1: Select all content and then filter. Press c

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

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 filter duplicate content in word How to filter duplicate content in word Mar 19, 2024 pm 07:01 PM

When it comes to filtering duplicate content, the first thing you may think of is filtering numerical values ​​in Excel. In fact, in Word, we can also filter duplicate text in documents. When you are not sure whether you have typed a word incorrectly, you can use the filter to take a look. This step is very convenient. The editor below will lead you to learn how to filter duplicate content in Word. Friends who want to learn, come and study hard! 1. First, we open the word document we want to filter on the computer, as shown in the figure below. 2. Then, we select the text we want to find, as shown by the red arrow in the picture below. 3. Press [ctrl+H] on the keyboard to bring up the find and replace command. The red arrow in the figure below points to the

How to set up and operate wps filtering? How to set up and operate wps filtering? Mar 20, 2024 pm 09:51 PM

When using WPS tables, we sometimes list all types of data in a table. If necessary, we have to select the data that meets the requirements for application. Selecting bit by bit greatly reduces work efficiency. If you can It is much more convenient to use some software functions to make selections. The wps filtering function can realize this operation. Let’s take a look at the operation sharing below. 1. First open the data that needs to be filtered on the computer (as shown below) 2. First select the table header and click "Start" (as shown below). 3. Then click “Filter” (as shown below). 4. Then you will find an inverted triangle behind the table header. Click on the inverted triangle behind "Math" (as shown below). 5. Then the filtering options will pop up, such as clicking "Number Filter"

The solution to the problem that Excel tables cannot be filtered The solution to the problem that Excel tables cannot be filtered Mar 14, 2024 am 10:20 AM

In daily life, I find that the Excel table cannot be filtered, what should I do? Excel is one of the most commonly used data processing tools, helping users to complete data entry and organization simply and quickly. In order to allow users to use Excel smoothly, let's take a look at the solutions to the problem that Excel tables cannot be filtered. 1. First open the Excel document and click the [View] option in the menu. 2. Click the [Freeze Window] option in the toolbar. 3. Then in the options that open, cancel the freeze setting. 4. You can re-screen after canceling.

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

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: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

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:

See all articles