Label htmlFor Attribute

Definition and usage

htmlFor Set or return the value of the label's (label) for attribute.

label for 属性 Define 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 属性:

labelObject.htmlFor

Set htmlFor 属性:

labelObject.htmlFor = id

Attribute Value

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

Technical Details

Return value: 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> Atribute para sa 'for'