Adds detach()
[jquery.git] / src / manipulation.js
index 0051bbc..1b8066f 100644 (file)
@@ -4,7 +4,12 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
        rxhtmlTag = /(<(\w+)[^>]*?)\/>/g,
        rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i,
        rinsideTable = /^<(thead|tbody|tfoot|colg|cap)/,
-       rtbody = /<tbody/i;
+       rtbody = /<tbody/i,
+       fcloseTag = function(all, front, tag){
+               return rselfClosing.test(tag) ?
+                       all :
+                       front + "></" + tag + ">";
+       };
 
 jQuery.fn.extend({
        text: function( text ) {
@@ -32,7 +37,7 @@ jQuery.fn.extend({
                                jQuery(this).wrapAll( html.apply(this, arguments) );
                        });
                }
-               
+
                if ( this[0] ) {
                        // The elements to wrap the target around
                        var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone();
@@ -178,7 +183,7 @@ jQuery.fn.extend({
                                        cached = true;
                                }
                        }
-                       
+
                        if ( !fragment ) {
                                fragment = (this[0].ownerDocument || this[0]).createDocumentFragment();
                                scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment );
@@ -244,18 +249,21 @@ jQuery.each({
 });
 
 jQuery.each({
-       remove: function( selector ) {
+       // keepData is for internal use only--do not document
+       remove: function( selector, keepData ) {
                if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
-                       if ( this.nodeType === 1 ) {
+                       if ( !keepData && this.nodeType === 1 ) {
                                cleanData( jQuery("*", this).add(this) );
                        }
 
-                       if ( this.parentNode ) {
-                               this.parentNode.removeChild( this );
-                       }
+                       this.parentNode && this.parentNode.removeChild( this );
                }
        },
 
+       detach: function( selector ) {
+               jQuery( this ).remove( selector, true )
+       },
+
        empty: function() {
                // Remove element nodes and prevent memory leaks
                if ( this.nodeType === 1 ) {
@@ -303,11 +311,7 @@ jQuery.extend({
                        // Convert html string into DOM nodes
                        if ( typeof elem === "string" ) {
                                // Fix "XHTML"-style tags in all browsers
-                               elem = elem.replace(rxhtmlTag, function(all, front, tag){
-                                       return rselfClosing.test(tag) ?
-                                               all :
-                                               front + "></" + tag + ">";
-                               });
+                               elem = elem.replace(rxhtmlTag, fcloseTag);
 
                                // Trim whitespace, otherwise indexOf won't work as expected
                                var tags = elem.replace(rleadingWhitespace, "")