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 ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.