Skip to content

Commit

Permalink
Fixes #13779. Remove nodes in document order (uses for loop matching …
Browse files Browse the repository at this point in the history
…empty()).
  • Loading branch information
rwaldron committed Apr 17, 2013
1 parent db0326b commit 77d7f26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/manipulation.js
Expand Up @@ -75,9 +75,10 @@ jQuery.fn.extend({
remove: function( selector, keepData ) { remove: function( selector, keepData ) {
var elem, var elem,
elems = selector ? jQuery.filter( selector, this ) : this, elems = selector ? jQuery.filter( selector, this ) : this,
i = elems.length; i = 0,
l = elems.length;


while ( i-- ) { for ( ; i < l; i++ ) {
elem = elems[ i ]; elem = elems[ i ];


if ( !keepData && elem.nodeType === 1 ) { if ( !keepData && elem.nodeType === 1 ) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/manipulation.js
Expand Up @@ -1572,6 +1572,30 @@ test( "remove() event cleaning ", 1, function() {
cleanUp.remove(); 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() { test( "detach()", 11, function() {
testRemove("detach"); testRemove("detach");
}); });
Expand Down

0 comments on commit 77d7f26

Please sign in to comment.