Note: jQuery
28 Jul 2014The .attr()
method
- setter:
$('a').attr('href', 'example.com')
- getter:
$('a').attr('href')
Selecting Elements
- By ID:
$('#myId')
- By Class Name:
$('.myClass')
- Compound:
$('#contents ul.people')
-
Pseudo-selectors:
$('a.external:first')
Does My Selection Contain Any Elements?
if ($('div.foo').length) {
// do things
}
Refining & Filtering Selections
// Refining selections.
$( "div.foo" ).has( "p" ); // div.foo elements that contain <p> tags
$( "h1" ).not( ".bar" ); // h1 elements that don't have a class of bar
$( "ul li" ).filter( ".current" ); // unordered list items with class of current
$( "ul li" ).first(); // just the first unordered list item
$( "ul li" ).eq( 5 ); // the sixth
Your Comments
comments powered by Disqus