Skip to content

Commit dd845a2

Browse files
committed
Fix #10812, let .before() and .after() work on empty collections.
1 parent 7c2d6c8 commit dd845a2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/manipulation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jQuery.fn.extend({
154154
this.parentNode.insertBefore( elem, this );
155155
});
156156
} else if ( arguments.length ) {
157-
var set = jQuery(arguments[0]);
157+
var set = jQuery.clean( arguments );
158158
set.push.apply( set, this.toArray() );
159159
return this.pushStack( set, "before", arguments );
160160
}
@@ -167,7 +167,7 @@ jQuery.fn.extend({
167167
});
168168
} else if ( arguments.length ) {
169169
var set = this.pushStack( this, "after", arguments );
170-
set.push.apply( set, jQuery(arguments[0]).toArray() );
170+
set.push.apply( set, jQuery.clean(arguments) );
171171
return set;
172172
}
173173
},

test/unit/manipulation.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,14 @@ test("before(Function)", function() {
794794
testBefore(functionReturningObj);
795795
})
796796

797+
test("before and after w/ empty object (#10812)", function() {
798+
expect(2);
799+
800+
var res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" );
801+
equal( res.length, 2, "didn't choke on empty object" );
802+
equal( res.wrap("<div/>").parent().text(), "()", "correctly appended text" );
803+
});
804+
797805
test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
798806
expect(4);
799807
var expected = "This is a normal link: bugaYahoo";

0 commit comments

Comments
 (0)