What does jquery use for filtering?
Filtering method: 1. Use ".hasClass("class name")" to filter class names; 2. Use ".eq(n)" to filter subscripts; 3. Use ".is(select (selector)" filter judgment; 4. Use ".not (selector or function)" to reverse filter; 5. Use ".filter (selector or function)" to filter expressions.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
What to use for jquery filtering
In jQuery, there are 5 common filtering methods:
1. Class name filtering: hasClass( );
Class name filtering refers to filtering based on the class of the element. In jQuery, we can use the hasClass() method to implement class name filtering.
Syntax:
$().hasClass("类名")
hasClass() method is generally used to determine whether the element contains the specified class name: if it does, it returns true; if it does not, it returns false.
2. Subscript filtering: eq();
Subscript filtering refers to filtering based on the subscript of the element collection. In jQuery, we can use the eq() method to implement subscript filtering.
Syntax:
$().eq(n)
n is an integer. When n takes the value 0 or a positive integer, eq(0) obtains the 1st element, eq(1) obtains the 2nd element,..., and so on. When n is a negative integer, eq(-1) obtains the first element from the last, eq(-2) obtains the second element from the last,..., and so on.
3. Judgment filtering: is();
Judgment filtering refers to judging based on certain conditions, and then selecting those that meet the conditions Elements. In jQuery, we can use the is() method to implement judgment filtering.
Syntax:
$().is(selector)
Parameter selector is a selector. The is() method is used to determine whether there is an element that meets the conditions in the currently selected element collection: if it exists, it returns true; if it does not exist, it returns false.
The is() method is very easy to use, and whether it can be used well directly determines whether your code is efficient. When developing with jQuery, there is nothing you can't do, only things you can't imagine. Listed below are the common function codes of the is() method:
//判断元素是否可见 $().is(":visible") //判断元素是否处于动画中 $().is(":animated") //判断单选框或复选框是否被选中 $().is(":checked") //判断当前元素是否为第一个子元素 $(this).is(":first-child") //判断文本中是否包含jQuery这个词 $().is(":contains('jQuery')") //判断是否包含某些类名 $().is(".select")
4. Reverse filtering: not();
in In jQuery, we can also use the not() method to filter elements that "do not meet the conditions" and return the remaining elements that meet the conditions. Among them, the not() method can use a selector to filter or a function to filter.
Syntax:
$().not(selector或fn)
When the not() method parameter is a selector, it means using the selector to filter elements that do not meet the conditions, and then select the remaining elements. When the parameter of the not() method is a function, it means using the function to filter elements that do not meet the conditions, and then select the remaining elements.
5. Expression filtering: filter(), has().
Expression filtering refers to using "custom expression" to select elements that meet the conditions. This custom expression can be a selector or a function.
In jQuery, there are two methods for expression filtering: one is the filter() method and the other is the has() method.
jQuery filter() method
In jQuery, the filter() method is a very powerful filtering method. It can use selectors to filter, or you can use function to filter.
1) Selector filtering
Selector filtering refers to using a selector to select elements that meet conditions.
Syntax:
$().filter(selector)
Parameter selector is a selector.
2) Function filtering
Function filtering refers to selecting elements that meet the conditions based on the return value of the function.
Syntax:
$().filter(fn)
The parameter fn is a callback function.
The filter() method is very powerful and includes almost all the functions of the filtering methods learned before. However, it is precisely because there are too many things encapsulated inside the filter() method that it runs very slowly. Therefore, in actual development, it is recommended that you give priority to other filtering methods and use the filter() method as a last resort.
jQuery has() method
In jQuery, in addition to using the filter() method for expression filtering, we can also use the has() method. Although the has() method is not as powerful as the filter() method, it runs faster.
Syntax:
$().has(selector)
Parameter selector is a selector.
The has() method has similar functions to the filter() method, but the has() method can only use selectors to filter, not functions. Therefore we can think of the has() method as a streamlined version of the filter() method.
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of What does jquery use for filtering?. 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

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,

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
