Skip to content
Permalink
Browse files

Adding some fixes for commit [6537]. If there's leading whitespace, o…

…r if an exception is thrown by innerHTML, we need to use the old style method.
  • Loading branch information
jeresig committed Sep 15, 2009
1 parent cf8c124 commit fc4c6915344625fadf55ca25d3cf9094544d301a
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/manipulation.js
@@ -189,15 +189,21 @@ jQuery.fn.extend({

// See if we can take a shortcut and just use innerHTML
} else if ( typeof value === "string" && !/<script/i.test( value ) &&
this[0] && !jQuery.isXMLDoc( this[0] ) &&
(!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("*") );
this[i].innerHTML = value;
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;
}
}

// If using innerHTML throws an exception, use the fallback method
} catch(e) {
this.empty().append( value );
}

} else {

0 comments on commit fc4c691

Please sign in to comment.
You can’t perform that action at this time.