cycling jQuery_Succinctly | Page 43

< a href =" http:// www. jquery. com " title =" jQuery " class =" foo "> jQuery. com 1 </ a > < a href =""> jQuery. com </ a >
< script src =" http:// ajax. googleapis. com / ajax / libs / jquery / 1.7.2 / jquery. min. js "></ script >
< script >
( function($) { // Alerts " 1 " alert($(' a [ title =" jQuery "][ href^ =" http://"]'). length);
})( jQuery);
</ script > </ body > </ html >
Notice in the code how we have stacked two filters to accomplish this selection. Other selector filters can be stacked besides just attribute filters. For example:
// Select the last < div > contained in the // wrapper set that contains the text " jQuery ". $(' div: last: contains(" jQuery ")') // Get all check boxes that are both visible and selected. $(': checkbox: visible: checked ')
The concept to take away is that selector filters can be stacked and used in combination.
Notes: You can also nest and stack filters— e. g. $(' p '). filter(': not(: first): not(: last)').
Nesting selector filters
Selector filters can be nested. This enables you to wield filters in a very concise and powerful manner. Below, I give an example of how you can nest filters to perform complex filtering.
Sample: sample31. html
<! DOCTYPE html > < html lang =" en "> < body > < div > javascript </ div > < div >< span class =" jQuery "> jQuery </ span ></ div > < div > javascript </ div > < div >< span class =" jQuery "> jQuery </ span ></ div >
43