Setting the label “for” attribute with JavaScript

Sometimes JavaScript offers unique names for element attributes, for example, CSS properties with words that are normally separated with dashes are camel case in JavaScript. The label element’s “for” attribute is no exception, in fact it’s probably the most unique one I’ve stumbled across, which is why I thought it was important to share. When you set the label “for” attribute with JavaScript you have to set it as “htmlFor” and of course give it the same value as the input element’s id that you are tying it to.

Tags: ,

Comments Closed

Comments are closed.