Quick Tip: Dissecting jQuery – Text


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.

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! :)


Other Episodes in the “Dissecting jQuery” Series

  1. Filters
  2. Grep

Leave a Reply

Your email address will not be published. Required fields are marked *