Attribute Selectors

Because jQuery supports both CSS and XPath-style expressions and the two conflict in their use of square brackets, jQuery adopts the XPath notation for attribute selectors, beginning them with the @ symbol.

When using any of the following attribute selectors, we should account for attributes that have multiple, space-separated values. Since these selectors see attribute values as a single string, this selector, for example, $('[a@rel=nofollow]'), will select <a rel="nofollow" href="example.html">Some text</a> but not <a rel="nofollow self" href="example.html">Some text</a>.

Attribute values in selector expressions can be written as bare words or surrounded by quotation marks. Therefore, the following variations are equally correct:

The variation we choose is generally a matter of style or convenience.

All elements that have the foo attribute.

Elements that have the foo attribute with a value exactly equal to bar.

All elements that do not have the foo attribute with a value exactly equal to bar.

All elements that have the foo attribute with a value beginning exactly with the string bar.

All elements that have the foo attribute with a value ending exactly with the string bar.

All elements that have the foo attribute with a value containing the substring bar.