diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2012-12-12 17:05:50 -0500 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2012-12-13 09:19:41 -0500 |
commit | 0018f7700bf8004d573c752ecbf66f299769c4de (patch) | |
tree | d6f2094bec52150ad0b0298748ec7b524b5c778e | |
parent | 40e08f81bd880afc5197ab145bce30d28e88c88f (diff) | |
download | jquery-0018f7700bf8004d573c752ecbf66f299769c4de.tar.gz jquery-0018f7700bf8004d573c752ecbf66f299769c4de.zip |
Fix #11230. .appendTo and pals should always stack.
-rw-r--r-- | src/manipulation.js | 14 | ||||
-rw-r--r-- | test/unit/manipulation.js | 10 |
2 files changed, 9 insertions, 15 deletions
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("<div/>").clone().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" ); - strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); - strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); - strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" ); + strictEqual( jQuery("<div/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" ); + strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); + strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); + strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" ); strictEqual( jQuery("<p/>").appendTo("<div/>").end().length, jQuery("<p>test</p>").appendTo("<div/>").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 "<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>", "<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>", "<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>" - ] ).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"); |