I have a little guess because I am not familiar with the jQuery source. jQuery.attr calls jQuery.access , and the comment above the jQuery.access function says:
// Multifunctional method to get and set values of a collection // The value/s can optionally be executed if it a function
Upon further investigation, the text() function also calls jQuery.access :
attr: function( name, value ) { return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 ); }, ......... text: function( value ) { return jQuery.access( this, function( value ) { ...... },
You use attr to install text handlers and events for which attr is not required. However, they all seem to use the same function to do the job, so using undocumented parameters just by chance gives you the expected behavior.
I would find it unacceptable to rely on undocumented behavior to accomplish what you are trying to do here, as any subsequent jQuery update could break your code.
bcoughlan
source share