JavaScript
Article

jQuery Attribute Selectors

By Sam Deering

Using attribute selectors in jQuery means you can easily find HTML web page elements without manually finding the elements inside the HTML which can often be like finding a needle in a haystack.

With jQuery attribute selectors you can manipulate HTML elements and create JavaScript variables from them, assign events to them, animate them, edit them and much more!

The beauty of these special selectors is that a simple jQuery attribute selector line can find and select several HTML elements all at the same time! Magic.

Here is how you do it:

$("[href]") //select all elements with an href attribute.

$("[href='#']") //select all elements with an href value equal to "#".

$("[href!='#']") //select all elements with an href attribute NOT equal to "#".

$("[href$='.jpg']") //select all elements with an href that ends with ".jpg".

Source: http://www.w3schools.com/jquery/jquery_selectors.asp

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.