aboutsummaryrefslogtreecommitdiffstats
path: root/src/manipulation.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2013-04-05 08:57:01 -0400
committerDave Methvin <dave.methvin@gmail.com>2013-04-06 16:37:32 -0400
commit1b610266502490eab42a0b9ddfac2f93da0b0fe1 (patch)
tree6588b3fcfc702725dc4fd16d7dcf0c16ff7b0396 /src/manipulation.js
parent5031c9db4bf22cc04472346eeee8f25a61c5ee68 (diff)
downloadjquery-1b610266502490eab42a0b9ddfac2f93da0b0fe1.tar.gz
jquery-1b610266502490eab42a0b9ddfac2f93da0b0fe1.zip
Fix #13721. Filter before .remove() loop so positionals work. Close gh-1221.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r--src/manipulation.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 5cfc853be..f3c729fdf 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -72,23 +72,21 @@ jQuery.fn.extend({
// keepData is for internal use only--do not document
remove: function( selector, keepData ) {
var elem,
- i = 0,
- l = this.length;
+ elems = selector ? jQuery.filter( selector, this ) : this,
+ i = elems.length;
- for ( ; i < l; i++ ) {
- elem = this[ i ];
+ while ( i-- ) {
+ elem = elems[ i ];
- if ( !selector || jQuery.filter( selector, [ elem ] ).length > 0 ) {
- if ( !keepData && elem.nodeType === 1 ) {
- jQuery.cleanData( getAll( elem ) );
- }
+ if ( !keepData && elem.nodeType === 1 ) {
+ jQuery.cleanData( getAll( elem ) );
+ }
- if ( elem.parentNode ) {
- if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
- setGlobalEval( getAll( elem, "script" ) );
- }
- elem.parentNode.removeChild( elem );
+ if ( elem.parentNode ) {
+ if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
+ setGlobalEval( getAll( elem, "script" ) );
}
+ elem.parentNode.removeChild( elem );
}
}