SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: getLabelByFor

  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getLabelByFor

    Greetings, I'm trying to write a generic function to get a <label> element by the for attribute. something similar to this. But it's not working. Do you see any problems?
    Code:
    function getLabelByFor(For)
    {
        var LblArr = document.getElementsByTagName('label');
        var CurrLbl;
        
        for (var i=0; i<LblArr.length; i++)
        {
            CurrLbl = LblArr[i].getAttribute('for');
            if (CurrLbl && CurrLbl == For)
            { return LblArr[i];}
        }
        return null;
    }

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    if you are testing in IE getAttribute('for') should be getAttribute('htmlFor')

    The same is with class IE does getAttribute('className')
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Intersting... Thanks logicearth


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •