http://www.learningjquery.com/2006/12/how-to-get-anything-you-want-part-2
filter will select a certain subset (zero or more) of the already
selected elements.find will select a set of (zero or more) elements that are descendants
of the already selected elements.Here is an example:
$('div').filter('.elephants'); // <-- selects the second div, because it has class="elephants"$('div').find('.elephants'); // <-- selects the first paragraph, because it has class="elephants"
* Note that these two examples are very simple and would probably be
better written as ...$('div.elephants');
... and ...
$('div .elephants');$('li + li > a[@href$=pdf]')
gets all links ending in
“pdf” that are children of any list item that has another list item as
its previous sibling. It won’t get the first list item’s silly.pdf
because that list item has no other list items before it.$('span:hidden')
gets any span element that is hidden.$('li:even')
gets all odd-numbered list items (because, in javascript, numbering starts with 0, not 1).$('li:lt(3)')
gets the first 3 list items. “lt” stands for “less than,” and it starts counting at 0, not 1.$('li:not(.goofy)')
gets list items 1, 2, and 4, because they’re not “goofy.”$('p a[@href*=#]')
gets any links that are inside a paragraph and have an “href” attributestarting with “#” —containing “#” anywhere.in other words, same-page links. There are problems with trying to identify same-page links this way. I’ll write about this in an upcoming entry. Note the space between the “p” and the “a”; that means that the “a” is a descendant of the “p.”
沒有留言:
張貼留言