Skip to content

Commit

Permalink
Fix #10517. before() and after() on disconnected node should return m…
Browse files Browse the repository at this point in the history
…ultiple nodes. Closes jquerygh-851.
  • Loading branch information
antishok authored and dmethvin committed Jul 10, 2012
1 parent b6cb4b4 commit f843a70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jQuery.fn.extend({
},

before: function() {
if ( this[0] && this[0].parentNode ) {
if ( !isDisconnected( this[0] ) ) {
return this.domManip(arguments, false, function( elem ) {
this.parentNode.insertBefore( elem, this );
});
Expand All @@ -155,7 +155,7 @@ jQuery.fn.extend({
},

after: function() {
if ( this[0] && this[0].parentNode ) {
if ( !isDisconnected( this[0] ) ) {
return this.domManip(arguments, false, function( elem ) {
this.parentNode.insertBefore( elem, this.nextSibling );
});
Expand Down Expand Up @@ -259,7 +259,7 @@ jQuery.fn.extend({
},

replaceWith: function( value ) {
if ( this[0] && this[0].parentNode && this[0].parentNode.nodeType != 11 ) {
if ( !isDisconnected( this[0] ) ) {
// Make sure that the elements are removed from the DOM before they are inserted
// this can help fix replacing a parent with child elements
if ( jQuery.isFunction( value ) ) {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,13 @@ test("before and after w/ empty object (#10812)", function() {
equal( res.wrapAll("<div/>").parent().text(), "()", "correctly appended text" );
});

test("before and after on disconnected node (#10517)", function() {
expect(2);

equal( jQuery("<input type='checkbox'/>").before("<div/>").length, 2, "before() returned all elements" );
equal( jQuery("<input type='checkbox'/>").after("<div/>").length, 2, "after() returned all elements" );
});

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

0 comments on commit f843a70

Please sign in to comment.