In this latest episode of “Dissecting jQuery,” we’ll discuss the text()
method, as well as a new feature, as of jQuery 1.4, that you may not be aware of yet.
Premium Members: Download this Video ( Must be logged in)
Subscribe to our YouTube page to watch all of the video tutorials!
jQuery Source for the text
Method
text: function( text ) { if ( jQuery.isFunction(text) ) { return this.each(function(i) { var self = jQuery(this); self.text( text.call(this, i, self.text()) ); }); } if ( typeof text !== "object" && text !== undefined ) { return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); } return jQuery.text( this ); }
Keep in mind that the ability to pass a function to the text()
method is only available, via the user of version 1.4 or higher. But that’s no problem; and if you’re still using 1.3, you should really stop!