
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Label Object
The HTML DOM Label Object in HTML represents the <label> element.
Syntax
Following is the syntax −
Creating a <label> element
var labelObject = document.createElement(“LABEL”)
Properties
Here, “LabelObject” can have the following properties −
Property | Description |
---|---|
Control | It returns the control of the label |
form | It returns a reference of enclosing form that contains the label |
htmlFor | It returns/sets the value of the for attribute of a label |
Example
Let us see an example for Label htmlForproperty −
<!DOCTYPE html> <html> <head> <title>Label htmlFor</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>Label-htmlFor</legend> <label id="CurrentEditor" for="editorTwo">Current Editor:</label><br> <input type="text" id="editorOne" placeholder="editorOne"> <input type="text" id="editorTwo" placeholder="editorTwo"> <input type="button" onclick="getEventData()" value="Change Editor"> <div id="divDisplay">Label for attribute set as editor two</div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var labelSelect = document.getElementById("CurrentEditor"); function getEventData() { if(labelSelect.htmlFor === 'editorTwo'){ divDisplay.textContent = 'Label for attribute set as editor one'; labelSelect.htmlFor = 'editorOne'; } } </script> </body> </html>
Output
This will produce the following output −
Before clicking ‘Change Editor’ button −
After clicking ‘Change Editor’ button −
- Related Articles
- HTML DOM Track label Property
- HTML DOM Option label Property
- HTML DOM Label htmlFor Property
- HTML DOM Object Object
- HTML DOM HTML Object
- HTML DOM Ins Object
- HTML DOM HR Object
- HTML DOM Variable Object
- HTML DOM aside Object
- HTML DOM Anchor Object
- HTML DOM TableData Object
- HTML DOM TableHeader Object
- HTML DOM TableRow Object
- HTML DOM Textarea Object
- HTML DOM Meter Object

Advertisements