Skip to content

Commit

Permalink
Manipulation: subtle change to innerHTML replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
yan committed Aug 23, 2015
1 parent a2092d8 commit e50c8ce
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ jQuery.fn.extend({

html: function( value ) {
return access( this, function( value ) {
var elem = this[ 0 ] || {},
var oldValue,
elem = this[ 0 ] || {},
i = 0,
l = this.length;

Expand All @@ -574,19 +575,21 @@ jQuery.fn.extend({
}

// See if we can take a shortcut and just use innerHTML
if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
oldValue = value;
value = typeof value === "string" && !rnoInnerhtml.test( value ) &&
( support.htmlSerialize || !rnoshimcache.test( value ) ) &&
( support.leadingWhitespace || !rleadingWhitespace.test( value ) ) &&
!wrapMap[ (rtagName.exec( value ) || [ "", "" ])[ 1 ].toLowerCase() ] ) {

value = value.replace( rxhtmlTag, "<$1></$2>" );
!wrapMap[ (rtagName.exec( value ) || [ "", "" ])[ 1 ].toLowerCase() ] &&
value.replace( rxhtmlTag, "<$1></$2>" );

if (value) {
try {
for (; i < l; i++ ) {
// Remove element nodes and prevent memory leaks
elem = this[i] || {};
if ( elem.nodeType === 1 ) {
jQuery.cleanData( getAll( elem, false ) );
// Sets innerHTML to "true" when processed by uglify-js@2.4.23
elem.innerHTML = value;
}
}
Expand All @@ -595,10 +598,10 @@ jQuery.fn.extend({

// If using innerHTML throws an exception, use the fallback method
} catch(e) {}
}
}

if ( elem ) {
this.empty().append( value );
this.empty().append( oldValue );
}
}, null, value, arguments.length );
},
Expand Down

0 comments on commit e50c8ce

Please sign in to comment.