Created
May 31, 2011 20:26
-
-
Save cduruk/1001204 to your computer and use it in GitHub Desktop.
jQuery's HTML Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html: function( value ) { | |
if ( value === undefined ) { | |
return this[0] && this[0].nodeType === 1 ? | |
this[0].innerHTML.replace(rinlinejQuery, "") : | |
null; | |
// See if we can take a shortcut and just use innerHTML | |
} else if ( typeof value === "string" && !rnocache.test( value ) && | |
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) && | |
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) { | |
value = value.replace(rxhtmlTag, "<$1></$2>"); | |
try { | |
for ( var i = 0, l = this.length; i < l; i++ ) { | |
// Remove element nodes and prevent memory leaks | |
if ( this[i].nodeType === 1 ) { | |
jQuery.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 if ( jQuery.isFunction( value ) ) { | |
this.each(function(i){ | |
var self = jQuery( this ); | |
self.html( value.call(this, i, self.html()) ); | |
}); | |
} else { | |
this.empty().append( value ); | |
} | |
return this; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment