It does "break the model" in some sense, but I think that is only because the API seems to be built from actual use rather than on a theorectical structure.
I can't honestly remember ever needing a list of the attributes of the objects I have selected. Mostly because you usually want to act on each object based on it's attributes. Most of the time I've needed to iterate through the list of objects (with each() or filter()), checking some attribute and doing something based on that. Karl Rudd On 5/1/07, Ariel Jakobovits <[EMAIL PROTECTED]> wrote:
Thanks for the response Mike. That "Getter methods like that generally return the value for the first matched element" doesn't make sense to me. Why? There's no need for this altered behavior. It breaks the jQuery model in my opinion. Unless I am missing something. Everything else in jQuery operates on arrays. I guess I am looking for someone to explain WHY the 'getter' functions operate this way from a design perspective. ----- Original Message ---- From: Mike Alsup <[EMAIL PROTECTED]> To: jquery-en@googlegroups.com Sent: Monday, April 30, 2007 8:20:54 PM Subject: [jQuery] Re: .attr() 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; }; And then call it like this: var arr = $('div').attrs("id"); Mike On 4/30/07, Ariel Jakobovits <[EMAIL PROTECTED]> wrote: > > I am looking for an explanation as to why .attr('id') executed on an array of jQuery elements does not return an array of ids. >