O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting the Previous Siblings

$("p#footer").prev("p")   //Finds the <p> element with id="footer" and   //selects the previous <p> element that is a sibling $("div#footer").prevAll("div");   //selects the <div> element with id="footer" and then   //selects all the <div> siblings prior to that element $("div#footer").prevUntil("div#header");   //finds the <div> element with id="footer" and then   //selects all prior siblings until #header is found

The .prev([selector]) method returns a jQuery object representing the previous sibling of each element in the current set. If the optional selector is provided, the previous sibling is added only if it matches the selector.

The .prevAll([selector]) method returns a jQuery ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required