Thanks to you both. Both approaches work. I appreciate the tips.

On Apr 6, 12:33 pm, "Andy Matthews" <[EMAIL PROTECTED]> wrote:
> Make that:
>
> $(document).ready( function() {
>
>         var myArr = [];
>         alert(myArr);
>         $('label').each( function() {
>                 myArr.push($(this).attr('for'));
>         });
>         alert(myArr);
>
> });
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
>
> Behalf Of Andy Matthews
> Sent: Friday, April 06, 2007 2:27 PM
> To: jquery-en@googlegroups.com
> Subject: [jQuery] Re: Getting all labels
>
> Maybe
>
> Var myArr = [];
> $('label').each(
>         myArr.push($(this).attr('for'));
> );
>
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of Buzzterrier
> Sent: Friday, April 06, 2007 2:13 PM
> To: jQuery (English)
> Subject: [jQuery] Getting all labels
>
> I want to get all labels in a form, and then access their "for"
> attribute to link it to the field.
>
> I thought that $("label") would give me an array of all label elements that
> I could loop through and get the "for" value. But this does not work and I
> know I am missing something fundamental to Jquery.
>
> If I do:
>
> $("label").attr("for");
>
> It gives me the first label in the fieldset, which is confusing.

Reply via email to