Label htmlFor Attribute

Definition and Usage

htmlFor Sets or returns the value of the label's (label) for attribute.

label for attribute Specifies which form element the label is bound to.

See also:

HTML Reference Manual:HTML <label> Tag

Example

Example 1

Return the value of the label's for attribute:

var x = document.getElementById("myLabel").htmlFor;

Try it yourself

Example 2

Change the value of the label's for attribute:

document.getElementById("myLabel").htmlFor = "newValue";

Try it yourself

Syntax

Return htmlFor attribute:

labelObject.htmlFor

Set htmlFor attribute:

labelObject.htmlFor = id

Attribute Value

Value Description
id The id of the element bound to the label (label).

Technical Details

Return Value: A string value representing the id of the element bound to the label (label).

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <label> for Attribute