02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

32<br />

CHAPTER 2 ■ COMMON JQUERY ACTIONS AND METHODS<br />

[ p ]<br />

To include the paragraph with an ID of bar, you need to look at the element immediately following,<br />

which is the form element in this case. Try the selector again using this updated code:<br />

$(".foo").nextUntil("form");<br />

Now, both following paragraphs are returned:<br />

>>> $(".foo").nextUntil("form");<br />

[ p, p#bar ]<br />

.prev(), .prevAll(), <strong>and</strong> .prevUntil()<br />

The .prev(), .prevAll(), <strong>and</strong> .prevUntil() functions work exactly like .next(), .nextAll(), <strong>and</strong><br />

.nextUntil(), except they look at previous sibling elements rather than next sibling elements:<br />

>>> $("#bar").prev();<br />

[ p ]<br />

>>> $("#bar").prevAll();<br />

[ p, p.foo, p ]<br />

>>> $("#bar").prevUntil(".foo");<br />

[ p ]<br />

.siblings()<br />

To select sibling elements on both sides of an element, use the .siblings() method. This accepts a<br />

selector as an argument to limit what types of elements are returned. To match all sibling paragraph<br />

elements to the paragraph with ID bar, execute the following code:<br />

$("#bar").siblings("p");<br />

The results will look as follows:<br />

>>> $("#bar").siblings("p");

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!