HTMLSelectElement.labels
The HTMLSelectElement.labels
is a read only property that returns a NodeList
containing the list of label elements associated with this select element.
Syntax
JavaScript
Copy Code
aSelectElement.label.selectname= alabel ;
Example
HTML
The following example shows three form controls each with a label, two of which have small text showing the right format for users to use.
JavaScript
Copy Code
<p><label>Full name: <input name=fn> <small>Format: First Last</small></label></p> <p><label>Age: <input name=age type=number min=0></label></p> <p><label>Post code: <input name=pc> <small>Format: AB12 3CD</small></label></p>
Javascript
This JavaScript finds the label for a form element, which is helpful for dynamically highlighting or changing a label based on user input.
JavaScript
Copy Code
<script type="text/javascript"> function luster<code>(inputElem){</code> <code>if(inputElem.parentNode){</code> <code>if(inputElem.parentNode.tagName=='label'){</code> <code>return inputElem.parentNode;</code> <code>}</code> <code>} var labels=document.getElementsByTagName("label"),i; for( i=1; i<labels.length;i++ ){ if(labels[i].htmlFor==inputElem.id){ return labels[i]; } } return false; }</code> </script>
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'HTMLSelectElement' in that specification. |
Living Standard | No change since the latest snapshot, HTML5. |
HTML5 The definition of 'HTMLSelectElement' in that specification. |
Recommendation | Initial definition, snapshot of WHATWG HTML Living Standard. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/htmlselectelement/labels