From f843a7062fef5a262c244575712b8173ced7c1a2 Mon Sep 17 00:00:00 2001 From: Uri Gilad Date: Tue, 10 Jul 2012 10:14:43 -0400 Subject: [PATCH] Fix #10517. before() and after() on disconnected node should return multiple nodes. Closes gh-851. --- src/manipulation.js | 6 +++--- test/unit/manipulation.js | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 282307b36..b248f51b8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -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 ); }); @@ -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 ); }); @@ -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 ) ) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 525c1387b..5d794b9bc 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -917,6 +917,13 @@ test("before and after w/ empty object (#10812)", function() { equal( res.wrapAll("
").parent().text(), "()", "correctly appended text" ); }); +test("before and after on disconnected node (#10517)", function() { + expect(2); + + equal( jQuery("").before("
").length, 2, "before() returned all elements" ); + equal( jQuery("").after("
").length, 2, "after() returned all elements" ); +}); + test("insertBefore(String|Element|Array<Element>|jQuery)", function() { expect(4); var expected = "This is a normal link: bugaYahoo"; -- 2.39.5