In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces "how to filter jquery" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to filter jquery" can help you solve your doubts.
Filtering methods: 1, use ".hasClass (" class name ")" to filter class names; 2, use ".eq (n)" to filter subscript; 3, use ".is (selector)" to filter judgment; 4, use ".not (selector or function)" reverse filter; 5, use ".filter (selector or function)" to filter expression.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
What does jquery filter with?
In jQuery, there are five common filtering methods:
1. Class name filtering: hasClass ()
Class name filtering, which refers to filtering based on the element's class. In jQuery, we can use the hasClass () method to implement class name filtering.
Syntax:
$() .hasClass (class name)
The hasClass () method is generally used to determine whether an 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 collection of elements. In jQuery, we can use the eq () method to implement subscript filtering.
Syntax:
() .eq (n)
N is an integer. When n is 0 or positive integer, eq (0) gets the first element, eq (1) gets the second element,... , and so on. When n is a negative integer, eq (- 1) gets the penultimate element, eq (- 2) gets the penultimate element,... , and so on.
3. Judge and filter: is ()
Judgment filtering refers to judging according to certain conditions, and then selecting elements that meet the conditions. In jQuery, we can use the is () method to implement decision filtering.
Syntax:
$() .is (selector)
The parameter selector is a selector. The is () method is used to determine whether there is a qualified element in the currently selected set of elements: if it does, it returns true;. If it does not, it returns false.
The is () method is very useful, and whether it can be used well or not directly determines whether your code is efficient or not. Using jQuery for development, there is nothing impossible, only unexpected. The following is a list of common functional codes for the is () method:
/ / determine whether the element is visible $(). Is (": visible") / / determine whether the element is in animation $(). Is (": animated") / / determine whether the checkbox or check box is selected $(). Is (": checked") / / determine whether the current element is the first child element $(this) .is (": first-child") / / determine whether the word jQuery is included in the text ). Is (": contains ('jQuery')") / / determine whether certain class names $(). Is (".select") 4, Reverse filtering: not ()
In jQuery, we can also use the not () method to filter elements that "do not meet the criteria" and return the remaining elements that meet the criteria. Where the not () method can be filtered using a selector or a function.
Syntax:
$() .not (selector or fn)
When the number of parameters of the not () method is a selector, it means to use the selector to filter elements that do not meet the criteria, and then select the rest of the elements. When the argument to the not () method is a function, it means to use the function to filter elements that do not meet the criteria, and then select the rest of the elements.
5. Expression filtering: filter (), has ().
Expression filtering refers to the use of "custom expressions" to select elements that meet the criteria. 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
The filter () method is a fairly powerful filtering method in jQuery, which can be filtered using selectors or functions.
1) Selector filter
Selector filtering refers to the use of selectors to select elements that meet the criteria.
Syntax:
$() .filter (selector)
The parameter selector is a selector.
2) function filtering
Function filtering refers to selecting qualified elements according to the return value of the function.
Syntax:
$() .filter (fn)
The parameter fn is a callback function.
The filter () method is so powerful that it almost includes the functionality of the filtering methods you've learned before. However, it is precisely because there are too many things encapsulated inside the filter () method that it runs very slowly. Therefore, in the actual development, it is recommended that we give priority to other filtering methods, and then use the filter () method as a last resort.
JQuery has () method
In jQuery, expression filtering can use the has () method as well as the filter () method. The has () method is not as powerful as the filter () method, but it runs faster.
Syntax:
$() .has (selector)
The parameter selector is a selector.
The has () method is similar to the filter () method, except that the has () method can only be filtered using selectors, not functions. So we can think of the has () method as a condensed version of the filter () method.
After reading this, the article "how to filter jquery" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.