Dissecting jquery – the text method

GFX9.COM share Dissecting jquery – the text method, you can download now.



In this latest episode of “Dissecting jQuery,” we’ll discuss the text(), as well as a new feature, as of jQuery 1.4, that you may not be aware of yet.


Also available in this series:

  1. Dissecting jQuery – Filters
  2. Dissecting jQuery – The Text Method


Full Screencast



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





Similar content