jquery's Attribute filter selector

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/woshisap/article/details/7341136

In an HTML document, the opening tag of an element usually contains multiple attributes (attribute), in jquery, in addition to the direct use of the ID and class attributes as selectors, it is also possible to select from a variety of attributes (such as title, etc.)

The element that is queried is filtered, and the attribute filter selector contains the brackets "[]" instead of a colon, usually using the "Selector [property filter selector]" syntax format, depending on whether the specified attribute is included or

Filters from the query to the element based on the property value.

1: Include attribute filter

Used to select all elements that contain a given property

Format: $ ("Selector[attribute]")

2: Attribute equals filter

Used to filter all elements of a given property equal to a particular value

$ ("selector[attribute=value]");

Example: $ ("input[name=accept]"). attr ("Checked", "true"); Select the check box with the name of accept

3: property contains filter

Used to select all elements of the specified property value containing the given string

Format: $ ("Selector[attribute*=value]")

Example: $ ("input[name*= ' News"). Val ("name contains the element with news"); Add a text value to the text box that contains ' news ' in name

4: attribute contains word filter

Lets you select elements in the specified property value that contain the given word (separated by spaces)

Format: $ ("selector[attribute~=value]");

Example: $ (' input[name~= ' News '). Val ("name contains the element of news word");

5: Attribute not equal to filter

Used to select all elements that do not contain a specified property, or that contain a specified property but that property does not equal a value

Format: $ ("Selector[attribute!=value]")

6: Property Start filter

Used to select all elements of a given property that begin with a specific value

Format: $ ("Selector[attribute^=value]")

7: End-of-property filter

Used to select all elements of a given property that end with a specific value

Format: $ ("Selector[attribute$=value]")

8: Composite Attribute Filter

Used to select all elements that meet multiple criteria at once

Format: $ ("Selector[selector1][selector2] ... [Selector[n] ")

Example: $ ("input[id][name^= ' News"). Val ("Compound condition"): Used to select a text box that contains an id attribute and the name value begins with ' News ' and set its value

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.