[Dojo-interest] Get labels for input element

Brian Duchek manxomfoe.lists at gmail.com
Thu Dec 7 12:01:01 MST 2006

As a tip on this topic, I flip-flop back and forth alot over using the
<label for... method of attachment, and the older <label><input>
nesting approach.  If you use the latter, it's much easier to find it
in the DOM.

I'm not 100% clear on which is more standards-compliant, or more
frequently used.


On 12/7/06, sam foster <potatosculptor at gmail.com> wrote:
> I dont think there's a direct way to get the label, you'll have to
> walk up the DOM to the enclosing FORM, and if you've still not found
> it (i.e. its not a container element around your input), do
> formElement.getElementsByTagName("label"), and loop over checking the
> "for" attribute to see if it matches the id of your input.
> Ugh. That's a lot of work. Sorry, I hope I'm wrong. I agree 100% with
> your approach though, and it would indeed be a useful  function in
> dojo. Performance might be improved with some caching, using xpath in
> FF, etc., which all make it good candidates for the framework and
> something the framework user shouldnt have to do.
> Sam
> > Can somebody tell me how to get the label tag's text for an input element?
> > I cannot found any javascript solution, so I think it would be really nice
> > to create a dojo solution for this.
> > It would be really useful as if you get it, you don't need to make
> > user-friendly/localize the name of the field
> > in an error message, as it is already done to display it as label.
> >
> > Or there is a solution just I can't find it?
> > Please help!
> > --
> > NP
> _______________________________________________
> Dojo FAQ: http://dojo.jot.com/FAQ
> Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
> Dojo-interest at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-interest

More information about the Dojo-interest mailing list