]> source.dussan.org Git - jquery.git/commitdiff
Fixes #13779. Remove nodes in document order (uses for loop matching empty()).
authorRick Waldron <waldron.rick@gmail.com>
Wed, 17 Apr 2013 02:16:12 +0000 (22:16 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 17 Apr 2013 02:18:44 +0000 (22:18 -0400)
src/manipulation.js
test/unit/manipulation.js

index 3747e09241c01a6015608e71e17e55bd3142f866..ac1bf2bbf977766044569de857ddfc0459a37125 100644 (file)
@@ -75,9 +75,10 @@ jQuery.fn.extend({
        remove: function( selector, keepData ) {
                var elem,
                        elems = selector ? jQuery.filter( selector, this ) : this,
-                       i = elems.length;
+                       i = 0,
+                       l = elems.length;
 
-               while ( i-- ) {
+               for ( ; i < l; i++ ) {
                        elem = elems[ i ];
 
                        if ( !keepData && elem.nodeType === 1 ) {
index 73ad67715b637547b615c337ab70c21422690435..30710da583ba1ffa7a2d8c99e5886ce1b984425f 100644 (file)
@@ -1572,6 +1572,30 @@ test( "remove() event cleaning ", 1, function() {
        cleanUp.remove();
 });
 
+test( "remove() in document order #13779", 1, function() {
+       var last,
+               cleanData = jQuery.cleanData;
+
+       jQuery.cleanData = function( nodes ) {
+               last = nodes[0].textContent;
+               cleanData.call( this, nodes );
+       };
+
+       jQuery("#qunit-fixture").append(
+               jQuery.parseHTML(
+                       "<div class='removal-fixture'>1</div>" +
+                       "<div class='removal-fixture'>2</div>" +
+                       "<div class='removal-fixture'>3</div>"
+               )
+       );
+
+       jQuery(".removal-fixture").remove();
+
+       equal( last, 3, "The removal fixtures were removed in document order" );
+
+       jQuery.cleanData = cleanData;
+});
+
 test( "detach()", 11, function() {
        testRemove("detach");
 });