Skip to content
Browse files
jQuery#addBack supports an optional selector that can be used to filt…
…er the prior set before adding it back. Fixes #9800
  • Loading branch information
cowboy authored and rwaldron committed May 29, 2012
1 parent 7f2cc46 commit 02dd7c570bf4dbbdfc168f4352d04c667447be5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
@@ -143,8 +143,9 @@ jQuery.fn.extend({
jQuery.unique( all ) );

addBack: function() {
return this.add( this.prevObject );
addBack: function( selector ) {
var prior = this.prevObject;

This comment has been minimized.

Copy link

scottgonzalez May 31, 2012


I think this temp var hurts gzip.

This comment has been minimized.

Copy link

cowboy May 31, 2012

Author Member

Let the byte-jockeys hack away!

This comment has been minimized.

Copy link

timmywil Jun 1, 2012


I like the var. Now when people ask if we have any priors, we can say yes. :)

return this.add( selector == null ? prior : prior.filter(selector) );

@@ -403,11 +403,12 @@ test("has(Arrayish)", function() {

test("addBack()", function() {
deepEqual( jQuery("#en").siblings().addBack().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
deepEqual( jQuery("#foo").children().addBack().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
deepEqual( jQuery("#sndp, #en").parent().addBack().get(), q("foo","sndp","en"), "Check for parent and self" );
deepEqual( jQuery("#groups").parents("p, div").addBack().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
deepEqual( jQuery("#select1 > option").filter(":first-child").addBack(":last-child").get(), q("option1a", "option1d"), "Should contain the last elems plus the *filtered* prior set elements" );

test("siblings([String])", function() {

0 comments on commit 02dd7c5

Please sign in to comment.