]> source.dussan.org Git - jquery.git/commitdiff
Fix #10517. before() and after() on disconnected node should return multiple nodes...
authorUri Gilad <antishok@gmail.com>
Tue, 10 Jul 2012 14:14:43 +0000 (10:14 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 10 Jul 2012 14:14:43 +0000 (10:14 -0400)
src/manipulation.js
test/unit/manipulation.js

index 282307b361d6f58be5d3777099b51c4c0c6eebed..b248f51b8136f3e6457f7194dd67312c38c56198 100644 (file)
@@ -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 ) ) {
index 525c1387b6bd491274c1d928910e43c39321583f..5d794b9bcafdcb49fb2491fc5745487cc7d0e2fb 100644 (file)
@@ -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";