jquery core: Closes #5189. Added a generic function to handle getting/setting key-value/setting a hash.

This commit is contained in:
Ariel Flesler 2009-09-09 21:14:28 +00:00
parent aadc268abf
commit d1285504fb
4 changed files with 36 additions and 71 deletions

View file

@ -1,34 +1,6 @@
jQuery.fn.extend({
attr: function( name, value ) {
var elem, options, isFunction = jQuery.isFunction(value);
if ( typeof name === "string" ) { // A single attribute
if ( value === undefined ) { // Query it on first element
return this.length ?
jQuery.attr( this[0], name ) :
null;
} else { // Set it on all elements
for ( var i = 0, l = this.length; i < l; i++ ) {
elem = this[i];
if ( isFunction )
value = value.call(elem,i);
jQuery.attr( elem, name, value );
}
}
} else { // Multiple attributes to set on all
options = name;
for ( var i = 0, l = this.length; i < l; i++ ) {
elem = this[i];
for ( name in options ) {
value = options[name];
if ( jQuery.isFunction(value) )
value = value.call(elem,i);
jQuery.attr( elem, name, value );
}
}
}
return this;
return access(this, name, value, true, jQuery.attr);
},
addClass: function( value ) {