• jQuery
  • jQuery UI
  • jQuery Mobile
  • Sizzle
  • QUnit
  • Plugins
  • Contribute
    • CLA
    • Style Guides
    • Bug Triage
    • Code
    • Documentation
    • Web Sites
  • Events
    • UK
    • Portland
  • Support
    • Learning Center
    • Try jQuery
    • IRC/Chat
    • Forums
    • Stack Overflow
    • Commercial Support
  • jQuery Foundation
    • Join
    • Members
    • Team
    • Brand Guide
    • Donate

jQuery API Documentation

  • Download
  • API Documentation
  • Blog
  • Plugins
  • Browser Support

Category: Attribute


The CSS specification allows elements to be identified by their attributes. While not supported by some older browsers for the purpose of styling documents, jQuery allows you to employ them regardless of the browser being used.

When using any of the following attribute selectors, you 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 href="example.html" rel="nofollow">Some text</a> but not <a href="example.html" rel="nofollow foe">Some text</a>.

Attribute values in selector expressions must follow the rules for W3C CSS selectors; in general, that means anything other than a valid identifier should be surrounded by quotation marks.

  • double quotes inside single quotes: $('a[rel="nofollow self"]')
  • single quotes inside double quotes: $("a[rel='nofollow self']")
  • escaped single quotes inside single quotes: $('a[rel=\'nofollow self\']')
  • escaped double quotes inside double quotes: $("a[rel=\"nofollow self\"]")

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

Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the “@” symbol from your selectors in order to make them work again.

Attribute Contains Prefix Selector [name|="value"]

Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).

Attribute Contains Selector [name*="value"]

Selects elements that have the specified attribute with a value containing the a given substring.

Attribute Contains Word Selector [name~="value"]

Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.

Attribute Ends With Selector [name$="value"]

Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

Attribute Equals Selector [name="value"]

Selects elements that have the specified attribute with a value exactly equal to a certain value.

Also in: Selectors > jQuery Extensions

Attribute Not Equal Selector [name!="value"]

Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value.

Attribute Starts With Selector [name^="value"]

Selects elements that have the specified attribute with a value beginning exactly with a given string.

Has Attribute Selector [name]

Selects elements that have the specified attribute, with any value.

Multiple Attribute Selector [name="value"][name2="value2"]

Matches elements that match all of the specified attribute filters.

  • Ajax
    • Global Ajax Event Handlers
    • Helper Functions
    • Low-Level Interface
    • Shorthand Methods
  • Attributes
  • Callbacks Object
  • Core
  • CSS
  • Data
  • Deferred Object
  • Deprecated
    • Deprecated 1.3
    • Deprecated 1.7
    • Deprecated 1.8
  • Dimensions
  • Effects
    • Basics
    • Custom
    • Fading
    • Sliding
  • Events
    • Browser Events
    • Document Loading
    • Event Handler Attachment
    • Event Object
    • Form Events
    • Keyboard Events
    • Mouse Events
  • Forms
  • Internals
  • Manipulation
    • Class Attribute
    • Copying
    • DOM Insertion, Around
    • DOM Insertion, Inside
    • DOM Insertion, Outside
    • DOM Removal
    • DOM Replacement
    • General Attributes
    • Style Properties
  • Miscellaneous
    • Collection Manipulation
    • Data Storage
    • DOM Element Methods
    • Setup Methods
  • Offset
  • Properties
    • Properties of jQuery Object Instances
    • Properties of the Global jQuery Object
  • Removed
  • Selectors
    • Attribute
    • Basic
    • Basic Filter
    • Child Filter
    • Content Filter
    • Form
    • Hierarchy
    • jQuery Extensions
    • Visibility Filter
  • Traversing
    • Filtering
    • Miscellaneous Traversing
    • Tree Traversal
  • Utilities
  • Version
    • Version 1.0
    • Version 1.0.4
    • Version 1.1
    • Version 1.1.2
    • Version 1.1.3
    • Version 1.1.4
    • Version 1.2
    • Version 1.2.3
    • Version 1.2.6
    • Version 1.3
    • Version 1.4
    • Version 1.4.1
    • Version 1.4.2
    • Version 1.4.3
    • Version 1.4.4
    • Version 1.5
    • Version 1.5.1
    • Version 1.6
    • Version 1.7
    • Version 1.8
    • Version 1.9

Quick Access

CDN
Download jQuery 1.9.1 →
  • GitHub jQuery
    Source
  • Forum Community
    Support
  • Bugs Issue
    Tracker

Books

  • Learning jQuery 3rd Edition by Karl Swedberg and Jonathan Chaffer Learning jQuery Third Edition
    Karl Swedberg and Jonathan Chaffer
  • jQuery in Action by Bear Bibeault and Yehuda Katz jQuery in Action
    Bear Bibeault and Yehuda Katz
  • jQuery Succinctly by Cody Lindley jQuery Succinctly
    Cody Lindley
  • Learning Center
  • Forum
  • API
  • Twitter
  • IRC

Copyright 2013 The jQuery Foundation.
Web hosting by Media Temple | Powered by WordPress | Thanks: Members, Sponsors