diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2013-04-05 08:57:01 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2013-04-06 16:37:32 -0400 |
commit | 1b610266502490eab42a0b9ddfac2f93da0b0fe1 (patch) | |
tree | 6588b3fcfc702725dc4fd16d7dcf0c16ff7b0396 /src/manipulation.js | |
parent | 5031c9db4bf22cc04472346eeee8f25a61c5ee68 (diff) | |
download | jquery-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.js | 24 |
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 ); } } |