Attribute filter selector in jquery selector details _ jquery

Source: Internet
Author: User
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

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.