The HTMLSelectElement.labels is a read only property that returns a NodeList containing the list of label elements associated with this select element.
aSelectElement.label.selectname= alabel ;
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.
<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>
This JavaScript finds the label for a form element, which is helpful for dynamically highlighting or changing a label based on user input.
<script type="text/javascript">
function luster(inputElem){
if(inputElem.parentNode){
if(inputElem.parentNode.tagName=='label'){
return inputElem.parentNode;
}
}
var labels=document.getElementsByTagName("label"),i;
for( i=1; i<labels.length;i++ ){
if(labels[i].htmlFor==inputElem.id){
return labels[i];
}
}
return false;
}
</script>
| 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. |
| 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) |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/labels