]> source.dussan.org Git - jquery.git/commitdiff
Fixes #13779. Remove nodes in document order
authorRick Waldron <waldron.rick@gmail.com>
Wed, 17 Apr 2013 02:26:22 +0000 (22:26 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Wed, 17 Apr 2013 02:26:22 +0000 (22:26 -0400)
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
src/manipulation.js
test/unit/manipulation.js

index aeeaddf3589d411b71c55a593bb00cbdfc3fb164..cf0024a55f06f70ed5787dc003e3499fbea2003b 100644 (file)
@@ -163,10 +163,9 @@ jQuery.fn.extend({
        remove: function( selector, keepData ) {
                var elem,
                        elems = selector ? jQuery.filter( selector, this ) : this,
-                       i = elems.length;
+                       i = 0;
 
-               while ( i-- ) {
-                       elem = elems[ i ];
+               for ( ; (elem = elems[i]) != null; i++ ) {
 
                        if ( !keepData && elem.nodeType === 1 ) {
                                jQuery.cleanData( getAll( elem ) );
index b912589518165e897239f421a1e3f014703a0730..2aef444ff150d296d743f71083428f40b8920af4 100644 (file)
@@ -1827,6 +1827,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");
 });