X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Label htmlFor Property

Label Object Reference Label Object

Example

Return the value of the for attribute of a label:

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

The result of x will be:

male

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

Internet Explorer Firefox Opera Google Chrome Safari

The form property is supported in all major browsers.


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 value attribute of a label:

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

Try it yourself »


Related Pages

HTML reference: HTML <label> for attribute


Label Object Reference Label Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook