Skip to content
Permalink
Browse files

Fix #10517. before() and after() on disconnected node should return m…

…ultiple nodes. Closes gh-851.
  • Loading branch information
antishok authored and dmethvin committed Jul 10, 2012
1 parent b6cb4b4 commit f843a7062fef5a262c244575712b8173ced7c1a2
Showing with 10 additions and 3 deletions.
  1. +3 −3 src/manipulation.js
  2. +7 −0 test/unit/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 ) ) {
@@ -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";

0 comments on commit f843a70

Please sign in to comment.
You can’t perform that action at this time.