From e572eed26983b42a7713b8cfef28ed5fadb25bd6 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 16 Apr 2013 22:26:22 -0400 Subject: [PATCH] Fixes #13779. Remove nodes in document order Signed-off-by: Rick Waldron --- src/manipulation.js | 5 ++--- test/unit/manipulation.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index aeeaddf35..cf0024a55 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -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 ) ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index b91258951..2aef444ff 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -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( + "
1
" + + "
2
" + + "
3
" + ) + ); + + jQuery(".removal-fixture").remove(); + + equal( last, 3, "The removal fixtures were removed in document order" ); + + jQuery.cleanData = cleanData; +}); + test( "detach()", 11, function() { testRemove("detach"); }); -- 2.39.5