Home > Web Front-end > JS Tutorial > body text

Detailed explanation of attribute filter selector of jquery selector_jquery

WBOY
Release: 2016-05-16 17:02:22
Original
1127 people have browsed it
Copy code The code is as follows:



Copy code The code is as follows:



Hello



DIV with ID test

football
volleyball
Basketball
Other
< /body>

1. [attribute] Usage
Definition: Match elements containing the given attribute
Copy code The code is as follows:

$("div[id]").addClass("highlight"); //Find all divs with ID attributes Element

2. [attribute=value] Usage
Definition: Match elements
where the given attribute is a specific value Copy code The code is as follows:

$("input[name='basketball']").attr("checked",true ); //The input element whose name attribute value is basketball is selected

3. [attribute!=value] usage
definition: matching the given attribute is not included Elements with a specific value
Copy code The code is as follows:

$("input[name !='basketball']").attr("checked",true); //The name attribute value is not selected for the input element of basketball
//This selector is equivalent to: not([attr=value]) To match elements that contain a specific attribute but are not equal to a specific value, use [attr]:not([attr=value])
$("input:not(input[name='basketball'])").attr ("checked",true);

4. [attribute^=value] Usage
Definition: Match elements where the given attribute starts with a certain value
Copy code The code is as follows:

$("input[name^='foot'] ").attr("checked",true); //Find all input elements whose name starts with 'foot'

5. [attribute$=value] Usage
Definition: Matches elements whose given attributes end with certain values ​​
Copy code The code is as follows:

$("input[name$='ball']").attr("checked",true); //Find all input elements whose name ends with 'ball'

6. [attribute*=value] Usage
Definition: Match the given attribute by elements containing certain values ​​
Copy Code The code is as follows:

$("input[name*='sket']").attr("checked",true); //Find all Name input element containing 'sket'

7. [selector1][selector2][selectorN] Usage
Definition: Composite attribute selector, which needs to satisfy multiple requirements at the same time Use
to copy the code . The code is as follows:

$("input[id][name $='ball']").attr("checked",true); //Find all attributes containing id and whose name attribute ends with ball
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