> what about "plural" functions that would return an array
> of the requested attribute values from all of the elements?

Your approach could be generalized for attributes (and css similarly) like
this--untested:

jQuery.fn.attrs = function(n,a){
  if ( a ) 
    return this.each(function(i){this.attr(n,a[i]);});
  a = [];
  for ( var i=0; i < n; i++ )
    a.push(this[i].attr(n));
  return a;
};

var isDisabled = $(".boxes").attrs("disabled");
isDisabled[0] = true;
isDisabled[1] = false;
$(".boxes").attrs("disabled", isDisabled);

If you pass an array as the second item then it sets the corresponding attrs
and returns the original jQuery object so you can continue to chain methods.
If you don't pass an array it retrieves the attrs as an array of values. 

Really, the current .attr() method could look to see if its second argument
was an array and do the same magic as above for setting values. The tricky
part is retrieving values, since Javascript doesn't have a feature like
Perl's wantarray to tell you whether the caller expects an array or not. I
guess that means we still need the pluralized form.



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to