var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rleadingWhitespace = /^\s+/,
- rxhtmlTag = /(<(\w+)[^>]*?)\/>/g,
+ rxhtmlTag = /(<([\w:]+)[^>]*?)\/>/g,
rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i,
- rtagName = /<(\w+)/,
+ rtagName = /<([\w:]+)/,
rtbody = /<tbody/i,
+ rhtml = /</,
fcloseTag = function(all, front, tag){
return rselfClosing.test(tag) ?
all :
});
},
+ unwrap: function() {
+ return this.parent().each(function(){
+ if ( !jQuery.nodeName( this, "body" ) ) {
+ jQuery( this ).replaceWith( this.childNodes );
+ }
+ }).end();
+ },
+
append: function() {
return this.domManip(arguments, true, function(elem){
if ( this.nodeType === 1 ) {
},
before: function() {
- return this.domManip(arguments, false, function(elem){
- this.parentNode.insertBefore( elem, this );
- });
+ if ( this[0] && this[0].parentNode ) {
+ return this.domManip(arguments, false, function(elem){
+ this.parentNode.insertBefore( elem, this );
+ });
+ } else if ( arguments.length ) {
+ var set = jQuery(arguments[0]);
+ set.push.apply( set, this.toArray() );
+ return this.pushStack( set, "before", arguments );
+ }
},
after: function() {
- return this.domManip(arguments, false, function(elem){
- this.parentNode.insertBefore( elem, this.nextSibling );
- });
+ if ( this[0] && this[0].parentNode ) {
+ return this.domManip(arguments, false, function(elem){
+ this.parentNode.insertBefore( elem, this.nextSibling );
+ });
+ } else if ( arguments.length ) {
+ var set = this.pushStack( this, "after", arguments );
+ set.push.apply( set, jQuery(arguments[0]).toArray() );
+ return set;
+ }
},
clone: function( events ) {
// See if we can take a shortcut and just use innerHTML
} else if ( typeof value === "string" && !/<script/i.test( value ) &&
+ (!jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
- for ( var i = 0, l = this.length; i < l; i++ ) {
- // Remove element nodes and prevent memory leaks
- if ( this[i].nodeType === 1 ) {
- cleanData( this[i].getElementsByTagName("*") );
+ try {
+ for ( var i = 0, l = this.length; i < l; i++ ) {
+ // Remove element nodes and prevent memory leaks
+ if ( this[i].nodeType === 1 ) {
+ cleanData( this[i].getElementsByTagName("*") );
+ this[i].innerHTML = value;
+ }
}
- this[i].innerHTML = value;
+ // If using innerHTML throws an exception, use the fallback method
+ } catch(e) {
+ this.empty().append( value );
}
} else {
},
replaceWith: function( value ) {
- return this.after( value ).remove();
+ if ( this[0] && this[0].parentNode ) {
+ return this.after( value ).remove();
+ } else {
+ return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
+ }
},
detach: function( selector ) {
if ( args[0] && args[0].parentNode && args[0].parentNode.nodeType === 11 ) {
results = { fragment: args[0].parentNode };
} else {
- results = buildFragment( args, this[0], scripts );
+ results = buildFragment( args, this, scripts );
}
first = results.fragment.firstChild;
if ( !elem ) { return; }
// Convert html string into DOM nodes
- if ( typeof elem === "string" ) {
+ if ( typeof elem === "string" && !rhtml.test( elem ) ) {
+ elem = context.createTextNode( elem );
+
+ } else if ( typeof elem === "string" ) {
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(rxhtmlTag, fcloseTag);
});
function cleanData( elems ) {
- for ( var i = 0, l = elems.length; i < l; i++ ) {
- var id = elems[i][expando];
- if ( id ) {
+ for ( var i = 0, elem, id; (elem = elems[i]) != null; i++ ) {
+ if ( (id = elem[expando]) ) {
delete jQuery.cache[ id ];
}
}