jquery Selector Attribute Filter selector detailed _jquery

Source: Internet
Author: User
Copy Code code as follows:

<style type= "Text/css" >
/* Highlighting * *
. highlight{
Background-color:gray
}
</style>

Copy Code code as follows:

<body>
<div>
<p>Hello</p>
</div>
<div id= "test" >id as Test div</div>
<input type= "checkbox" id= "S1" name= "Football" value= "football"/> Football
<input type= "checkbox" name= "Volleyball" value= "Volleyball"/> Volleyball
<input type= "checkbox" id= "S3" Name= "basketball" value= "basketball"/> Basketball
<input type= "checkbox" id= "S4" Name= "other" value= "others"/> Other
</body>

1. [Attribute] Usage
Definition: Matches the element that contains the given property
Copy Code code as follows:

$ ("Div[id]"). AddClass ("highlight"); Find all DIV elements that contain ID attributes

2. [Attribute=value] Usage
Definition: Matches the given property is an element of a particular value
Copy Code code as follows:

$ ("Input[name= ' basketball ']"). attr ("Checked", true); The Name property value is basketball INPUT element selected

3. [Attribute!=value] Usage
Definition: Matching a given property is an element that does not contain a specific value
Copy Code code as follows:

$ ("input[name!= ' basketball ']"). attr ("Checked", true); The Name property value is not selected for basketball INPUT element
This selector is equivalent to: not ([Attr=value]) to match elements that contain specific attributes but not equal to a particular value, use [Attr]:not ([Attr=value])
$ ("Input:not (input[name= ' basketball ')"). attr ("Checked", true);

4. [Attribute^=value] Usage
Definition: Matches a given property as an element starting with some value
Copy Code code as follows:

$ ("input[name^= ' foot ']"). attr ("Checked", true); Find all input elements with ' foot ' started in name

5. [Attribute$=value] Usage
Definition: Matches the given property is an element that ends with some value
Copy Code code as follows:

$ ("input[name$= ' Ball ']"). attr ("Checked", true); Find all input elements with name ending with ' ball '

6. [Attribute*=value] Usage
Definition: Matches a given property to an element that contains certain values
Copy Code code as follows:

$ ("input[name*= ' sket ']"). attr ("Checked", true); Find all input elements with ' sket ' in name

7. [Selector1][selector2][selectorn] Usage
Definition: Composite property selector, which needs to be satisfied with multiple conditions
Copy Code code as follows:

$ ("input[id][name$= ' Ball ']"). attr ("Checked", true); All of the ID attributes are found, and its Name property ends with Ball

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.