Label htmlFor Property
Example
Return the value of the for attribute of a label:
var x = document.getElementById("myLabel").htmlFor;
The result of x will be:
male
Try it yourself »
Definition and Usage
The htmlFor property sets or returns the value of the for attribute of a label.
The for attribute specifies which form element a label is bound to.
Browser Support
The form property is supported in all major browsers.
Syntax
Return the htmlFor property:
labelObject.htmlFor
Set the htmlFor property:
labelObject.htmlFor=id
Property Values
Value | Description |
---|---|
id | The id of the element the label is bound to |
Technical Details
Return Value: | A String, representing the id of the element the label is bound to |
---|
More Examples
Example
Change the value of the value attribute of a label:
document.getElementById("myLabel").htmlFor = "newValue";
Try it yourself »
Related Pages
HTML reference: HTML <label> for attribute
Label Object