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 = /<|&\w+;/,
fcloseTag = function(all, front, tag){
return rselfClosing.test(tag) ?
all :
jQuery.fn.extend({
text: function( text ) {
- if ( typeof text !== "object" && text !== undefined )
+ if ( typeof text !== "object" && text !== undefined ) {
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
+ }
var ret = "";
- jQuery.each( text || this, function(){
- jQuery.each( this.childNodes, function(){
- if ( this.nodeType !== 8 ) {
- ret += this.nodeType !== 1 ?
- this.nodeValue :
- jQuery.fn.text( [ this ] );
- }
- });
+ jQuery.each( this, function() {
+ // Get the text from text nodes and CDATA nodes
+ if ( this.nodeType === 3 || this.nodeType === 4 ) {
+ ret += this.nodeValue;
+
+ // Traverse everything else, except comment nodes
+ } else if ( this.nodeType !== 8 ) {
+ ret += jQuery.fn.text.call( this.childNodes );
+ }
});
return ret;
});
},
+ 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 ) {
return this.domManip(arguments, false, function(elem){
this.parentNode.insertBefore( elem, this );
});
- } else {
- var set = jQuery.isFunction(arguments[0]) ?
- jQuery( arguments[0]() ) :
- jQuery.apply(jQuery, arguments);
-
- return this.pushStack( set.add( this ), "before", arguments );
+ } else if ( arguments.length ) {
+ var set = jQuery(arguments[0]);
+ set.push.apply( set, this.toArray() );
+ return this.pushStack( set, "before", arguments );
}
},
return this.domManip(arguments, false, function(elem){
this.parentNode.insertBefore( elem, this.nextSibling );
});
- } else {
- return jQuery.isFunction(arguments[0]) ?
- this.add( arguments[0]() ) :
- this.add.apply( this, arguments );
+ } else if ( arguments.length ) {
+ var set = this.pushStack( this, "after", arguments );
+ set.push.apply( set, jQuery(arguments[0]).toArray() );
+ return set;
}
},
// 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 {
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;
jQuery.each({
// keepData is for internal use only--do not document
remove: function( selector, keepData ) {
- if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
+ if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
if ( !keepData && this.nodeType === 1 ) {
cleanData( this.getElementsByTagName("*") );
cleanData( [ this ] );
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 ];
}
}