Label htmlFor Property
Example
Return the value of the for attribute of a label:
var x = document.getElementById("myLabel").htmlFor;
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
Property | |||||
---|---|---|---|---|---|
htmlFor | Yes | Yes | Yes | Yes | Yes |
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 for attribute of a label:
document.getElementById("myLabel").htmlFor = "newValue";
Try it Yourself »
Related Pages
HTML reference: HTML <label> for attribute
❮ Label Object