Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

HTMLSelectElement.labels

This article needs a technical review. How you can help.

The HTMLSelectElement.labels is a read only property that returns a NodeList containing the list of label elements associated with this select element.

Syntax

Edit

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.

<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.

<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>

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)

Document Tags and Contributors

 Contributors to this page: Rakhisharma
 Last updated by: Rakhisharma,