]> source.dussan.org Git - jquery.git/commitdiff
jQuery#addBack supports an optional selector that can be used to filter the prior...
authorBen Alman <cowboy@rj3.net>
Tue, 29 May 2012 16:04:27 +0000 (12:04 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Tue, 29 May 2012 16:04:27 +0000 (12:04 -0400)
src/traversing.js
test/unit/traversing.js

index d9be9c7e6f9eab924c5324cc2b89bac3a7e87ba7..7a9c60f912ccafc91be94741af0bd3845e0f50e3 100644 (file)
@@ -143,8 +143,9 @@ jQuery.fn.extend({
                        jQuery.unique( all ) );
        },
 
-       addBack: function() {
-               return this.add( this.prevObject );
+       addBack: function( selector ) {
+               var prior = this.prevObject;
+               return this.add( selector == null ? prior : prior.filter(selector) );
        }
 });
 
index 3400ffea8f6c520a5ebd066785c2ce77270f6dd5..7100342c7f79a0505ca2b48abfa5f2ad7aa66322 100644 (file)
@@ -403,11 +403,12 @@ test("has(Arrayish)", function() {
 });
 
 test("addBack()", function() {
-       expect(4);
+       expect(5);
        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() {