getAttribute in IE

Discussion in 'Javascript' started by jeff, Dec 20, 2009.

  1. jeff

    jeff Guest

    I'm doing a little form field checking:

    <label for="field_one">Field One</label>

    I'd like to know the "for" value.

    In Firefox I can do:

    label_reference.getAttribute("for").

    In IE (I'm testing in IE6 at the moment), I get "null", not what I was
    hoping for!


    How do I do this?

    Jeff
     
    jeff, Dec 20, 2009
    #1
    1. Advertising

  2. jeff

    jeff Guest

    jeff wrote:
    > I'm doing a little form field checking:
    >
    > <label for="field_one">Field One</label>
    >
    > I'd like to know the "for" value.
    >
    > In Firefox I can do:
    >
    > label_reference.getAttribute("for").
    >
    > In IE (I'm testing in IE6 at the moment), I get "null", not what I was
    > hoping for!


    Turns out to be: htmlFor

    doing:

    for (var x in label_reference)

    turned up that, and it seems like a thousand others!

    Jeff
    >
    >
    > How do I do this?
    >
    > Jeff
     
    jeff, Dec 20, 2009
    #2
    1. Advertising

  3. jeff

    David Mark Guest

    On Dec 20, 11:25 am, jeff <> wrote:
    > jeff wrote:
    > >  I'm doing a little form field checking:

    >
    > > <label for="field_one">Field One</label>

    >
    > >   I'd like to know the "for" value.

    >
    > >   In Firefox I can do:

    >
    > > label_reference.getAttribute("for").

    >
    > > In IE (I'm testing in IE6 at the moment), I get "null", not what I was
    > > hoping for!

    >
    > Turns out to be: htmlFor


    That's the property name as - for - is a reserved word, it can't be
    used as a property name. It's the same reason that the - class -
    attribute value is referenced by the - className - property. IE < 8
    and compatibility mode confuse attributes and properties, so it is
    best to avoid getAttribute whenever possible (virtually always in
    HTML). Just reference the property:-

    label_reference.htmlFor

    >
    > doing:
    >
    > for (var x in  label_reference)
    >
    > turned up that, and it seems like a thousand others!


    Those are properties.
     
    David Mark, Dec 20, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DN
    Replies:
    2
    Views:
    11,828
  2. Replies:
    3
    Views:
    2,898
  3. Rob
    Replies:
    4
    Views:
    8,588
    Brian A Palmer
    Sep 14, 2003
  4. Replies:
    2
    Views:
    10,396
  5. VitaminB
    Replies:
    1
    Views:
    807
    Oliver Wong
    Apr 26, 2006
Loading...

Share This Page