Label htmlForProperty

Label 对象参考手册Label Object

Examples

Return the value of the label's for attribute:

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

xThe output result is:

male

Try it Yourself »

Definition and Usage

The htmlFor property sets or returns the value of the label's for attribute.

The for attribute specifies which form element the label is to be bound to.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the htmlFor property.


Syntax

Return the htmlFor property:

labelObject.htmlFor

Set the htmlFor property:

labelObject.htmlFor=id

Property Values

Value Description
id The id of the element to which the label is to be bound.

Technical Details

Return Value: A string representing the id of the element to which the label is to be bound.


More Examples

Example

Change the value of the label's value attribute:

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

Try it Yourself »


Related Articles

HTML Reference Manual:HTML <label> for Attribute


Label 对象参考手册Label Object

Other Extensions