Home > Web Front-end > JS Tutorial > jQuery filter selector usage analysis_jquery

jQuery filter selector usage analysis_jquery

WBOY
Release: 2016-05-16 16:14:49
Original
1269 people have browsed it

The example in this article describes the usage of jQuery filter selector. Share it with everyone for your reference. The specific analysis is as follows:

In practice, a filter selector can be added to the basic selector to complete the query task. Depending on the specific situation, the index value, content, attributes, sub-element position, and form of the element can be used in the filter selector

Domain attributes and visibility as filter conditions

1. :first selector

Format:

Copy code The code is as follows:
$("selector: first")
is used Filter the current jQuery collection and select the first matching element

Example:

Copy code The code is as follows:
$("td:first").css("border ", "2px solid blue");

2. :last selector

Format:

Copy code The code is as follows:
$("selector: last")
is used Filter the current jQuery collection and select the last matching element
Example:
Copy code The code is as follows:
$("td:last").css("border", " 2px solid blue");

3. :odd selector

Format:

Copy code The code is as follows:
$("selector: odd")
is used Select all elements with odd index (counting from 0)

Example:

Copy code The code is as follows:
$("td:odd").css("background ", "red");

4. :even selector

Format:

Copy code The code is as follows:
$("selector: even")
is used Select all elements with even index (counting from 0)

Example:

Copy code The code is as follows:
$("td:even").css("background ", "red");

5. :eq selector

Format:

Copy code The code is as follows:
$("selector:eq(index)")
Used to select the element whose index is equal to the given value from the matching set

Example:

Copy code The code is as follows:
$("li:eq(1)").css ("color", "blue");

6. :gt selector

Format:

Copy code The code is as follows:
$("selector:gt(index)")
Used to select all elements from a matched set with index greater than a given value

Example:

Copy code The code is as follows:
$("li:gt(0)").css ("color", "green");

7. :lt selector

Format:

Copy code The code is as follows:
$("selector:lt(index)")
Used to select all elements from a matched set with index greater than a given value

Example:

Copy code The code is as follows:
$("li:lt(5)").css ("color", "green");

To find all elements with index greater than n1 and less than n2, you can use array selector,

Copy code The code is as follows:
$("selector:gt(n1), selector:lt(n2)") ;

8. :not selector

Format:

Copy code The code is as follows:
$("selector1:not(selector2)")
Used to remove all elements matching the given selector from the matched set

Example:

Copy code The code is as follows:
$("td:not(:first, :last) ").css("background", "red"); //Except for the first and last cells, the background color of other cells is red

9. :header selector

Format:

Copy code The code is as follows:
$(":header")
for selection All heading elements like h1, h2, h3

10. :animated selector

Format:

Copy code The code is as follows:
$("selector:animated")
is used Select all elements that are performing animation

Simple example:

Copy code The code is as follows:
 
 
 
 
过滤选择器 
 
 
 
 

简单过滤选择器应用示例

 
 
   
     
     
     
     
     
   
   
     
     
     
     
     
   
   
     
     
     
     
     
   
 

效果图如下所示:

希望本文所述对大家的jQuery程序设计有所帮助。

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template