This article mainly introduces the attribute filter selector of the jquery selector. If you need a friend, please refer to it and hope to help you.
The Code is as follows:
The Code is as follows:
Hello
DIV with ID test
Football
Volleyball
Basketball
Others
1. [attribute] usage
Definition: match an element that contains a given attribute
The Code is as follows:
$ ("P [id]"). addClass ("highlight"); // you can find all the p elements that contain the ID attribute.
2. [attribute = value] usage
Definition: matching a given attribute is an element of a specific value
The Code is as follows:
$ ("Input [name = 'bucketball ']"). attr ("checked", true); // select the input element whose attribute value is basketball
3. [attribute! = Value] usage
Definition: matching a given attribute is an element that does not contain a specific value.
The Code is as follows:
$ ("Input [name! = 'Bucketball'] "). attr (" checked ", true); // The value of the name attribute is not selected for the input element of the basketball.
// This selector is equivalent to: not ([attr = value]) to match an element that contains a specific attribute but is not equal to a specific value, use [attr]: not ([attr = value])
$ ("Input: not (input [name = 'bucketball '])"). attr ("checked", true );
4. [attribute ^ = value] usage
Definition: matching a given attribute is an element starting with some values
The Code is as follows:
$ ("Input [name ^ = 'foot']"). attr ("checked", true); // query all input elements whose names start with 'foot'
5. [attribute $ = value] usage
Definition: match an element whose given attribute ends with some values.
The Code is as follows:
$ ("Input [name $ = 'ball']"). attr ("checked", true); // query all input elements whose names end with 'ball'
6. [attribute * = value] usage
Definition: matching a given property is an element that contains certain values.
The Code is as follows:
$ ("Input [name * = 'sket ']"). attr ("checked", true); // find all input elements whose names contain 'sket'
7. [selector1] [selector2] [selectorN] usage
Definition: Composite attribute selector, which must meet multiple conditions at the same time
The Code is as follows:
$ ("Input [id] [name $ = 'ball']"). attr ("checked", true); // find all the attributes that contain the id and whose name attribute ends with the ball