From: Dave Methvin Date: Wed, 12 Dec 2012 22:05:50 +0000 (-0500) Subject: Fix #11230. .appendTo and pals should always stack. X-Git-Tag: 1.9.0b1~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0018f7700bf8004d573c752ecbf66f299769c4de;p=jquery.git Fix #11230. .appendTo and pals should always stack. --- diff --git a/src/manipulation.js b/src/manipulation.js index b9d5f0ff1..40885e95c 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -512,21 +512,15 @@ jQuery.each({ i = 0, ret = [], insert = jQuery( selector ), - l = insert.length, - parent = this.length === 1 && this[0].parentNode; + last = insert.length - 1; - if ( (parent == null || parent && parent.nodeType === 11 && parent.childNodes.length === 1) && l === 1 ) { - insert[ original ]( this[0] ); - return this; - } else { - for ( ; i < l; i++ ) { - elems = ( i > 0 ? this.clone(true) : this ).get(); + for ( ; i <= last; i++ ) { + elems = i === last ? this : this.clone(true); jQuery( insert[i] )[ original ]( elems ); - ret = ret.concat( elems ); + core_push.apply( ret, elems.get() ); } return this.pushStack( ret ); - } }; }); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 41db7291d..af063b059 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2092,10 +2092,10 @@ test( "Ensure oldIE creates a new set on appendTo (#8894)", function() { expect( 5 ); - strictEqual( jQuery("
").clone().addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" ); - strictEqual( jQuery("
").find("p").end().addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); - strictEqual( jQuery("
").text("test").addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); - strictEqual( jQuery("").clone().addClass("test").appendTo("
").end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" ); + strictEqual( jQuery("
").clone().addClass("test").appendTo("
").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" ); + strictEqual( jQuery("
").find("p").end().addClass("test").appendTo("
").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); + strictEqual( jQuery("
").text("test").addClass("test").appendTo("
").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); + strictEqual( jQuery("").clone().addClass("test").appendTo("
").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" ); strictEqual( jQuery("

").appendTo("

").end().length, jQuery("

test

").appendTo("
").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" ); }); @@ -2292,7 +2292,7 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e "
  • c1
    h1
  • c2
    h2
", "
1
2
3
", "
1
2
" - ] ).appendTo( "#qunit-fixture" ); + ].join("") ).appendTo( "#qunit-fixture" ); // complex case based on http://jsfiddle.net/pbramos/gZ7vB/ jQuery("#test4087-complex div")[ name ]("#test4087-complex li:last-child div:last-child");