Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
jQuery addPrior: Add the previous set's elements (before the last filter / traversal) to the current set, optionally filtering them. Supersedes jQuery's built-in .andSelf method.
jQuery.fn.addPrior = function(selector) {
var prior = this.prevObject;
return this.add(selector == null ? prior : prior.filter(selector));
};
// BASIC
// select UL + all LI children:
$("ul").children("li").addPrior()
// MORE COMPLEX
// select both first and last children:
$("li").filter(":first-child").addPrior(":last-child")
// FIND+FILTER
var elems = $(something);
// lame:
elems.find("li").add(elems.filter("li"))
// sexy:
elems.find("li").addPrior("li")
@cowboy
Owner

See jQuery ticket #9800 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.