jQuery [attribute|=value]Selector

jQuery 选择器jQuery Selectors

Examples

Select all <p> elements with a title attribute that starts with "Tomorrow":

$("p[title|='Tomorrow']")

Try it Yourself »

Definition and Usage

The [attribute|=value] selector selects each element with a specified attribute whose value is equal to the specified string (e.g., "en") or begins with that string followed by a hyphen (e.g., "en-us").

Tip:This selector is often used to handle the language attribute.


Syntax

$("[attribute|='value']")

Parameter Description
attribute Required. Specifies the attribute to find.
value Required. Specifies the string that the attribute value must start with.


实例s

More Examples

Handling the language attribute
This example selects all <a> elements with an hreflang attribute that starts with the value "en".

jQuery 选择器jQuery Selectors

Other Extensions