Skip to content

Commit

Permalink
Fix #10812, let .before() and .after() work on empty collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Nov 17, 2011
1 parent 7c2d6c8 commit dd845a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/manipulation.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jQuery.fn.extend({
this.parentNode.insertBefore( elem, this ); this.parentNode.insertBefore( elem, this );
}); });
} else if ( arguments.length ) { } else if ( arguments.length ) {
var set = jQuery(arguments[0]); var set = jQuery.clean( arguments );
set.push.apply( set, this.toArray() ); set.push.apply( set, this.toArray() );
return this.pushStack( set, "before", arguments ); return this.pushStack( set, "before", arguments );
} }
Expand All @@ -167,7 +167,7 @@ jQuery.fn.extend({
}); });
} else if ( arguments.length ) { } else if ( arguments.length ) {
var set = this.pushStack( this, "after", arguments ); var set = this.pushStack( this, "after", arguments );
set.push.apply( set, jQuery(arguments[0]).toArray() ); set.push.apply( set, jQuery.clean(arguments) );
return set; return set;
} }
}, },
Expand Down
8 changes: 8 additions & 0 deletions test/unit/manipulation.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -794,6 +794,14 @@ test("before(Function)", function() {
testBefore(functionReturningObj); testBefore(functionReturningObj);
}) })


test("before and after w/ empty object (#10812)", function() {
expect(2);

var res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" );
equal( res.length, 2, "didn't choke on empty object" );
equal( res.wrap("<div/>").parent().text(), "()", "correctly appended text" );
});

test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4); expect(4);
var expected = "This is a normal link: bugaYahoo"; var expected = "This is a normal link: bugaYahoo";
Expand Down

0 comments on commit dd845a2

Please sign in to comment.