diff options
-rw-r--r-- | src/traversing.js | 5 | ||||
-rw-r--r-- | test/unit/traversing.js | 3 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/traversing.js b/src/traversing.js index d9be9c7e6..7a9c60f91 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -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) ); } }); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 3400ffea8..7100342c7 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -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() { |