Mike Alsup schrieb:

That's just not what it does.  Getter methods like that generally
return the value for the first matched element.  If you want a plugin
to return all the values in an array you can write it like this
(untested):

jQuery.fn.attrs = function(key,val) {
   if (val != undefined)
       return this.each(function() {
           $(this).attr(key,val);
       });
   var a = [];
   this.each(function() { a.push($(this).attr(key)); });
   return a;
};
You don't even need the explicit loop:

jQuery.fn.attrs = function(key, val) {
  if (val != undefined)
      return this.attr(key, val);
  var a = [];
  this.each(function() { a.push($(this).attr(key)); });
  return a;
};

Now I'll wait for Dave to show up and write that in two lines :-)

--
Jörn Zaefferer

http://bassistance.de

Reply via email to