Label htmlFor property
Example
Return the value of the for attribute of the label:
var x = document.getElementById("myLabel").htmlFor;
x The output is:
male
Try it »
Definition and Usage
The htmlFor property sets or returns the value of the for attribute of the label.
The for attribute specifies which form element the label is bound to.
Browser support





All major browsers support the htmlFor property.
Syntax
Return the htmlFor property:
labelObject
.htmlFor
Set the htmlFor property:
labelObject
.htmlFor=
id
Attribute values
| Value | Description |
|---|---|
| id | The id of the element that the label is bound to. |
Technical Details
| Return Value: | String, representing the id of the element that the label is bound to. |
|---|
More examples
Example
Change the value of the value attribute of the label:
document.getElementById("myLabel").htmlFor="newValue";
Try it »
Related Articles
HTML Reference Manual:HTML
Label Object