6

What is the label attribute of & lt; option & gt; really used?

 3 years ago
source link: https://www.codesd.com/item/what-is-the-label-attribute-of-option-really-used.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What is the label attribute of & lt; option & gt; really used?

advertisements

According to the w3 XHTML specification, the label attribute specifies a shorter label for the option. However (using the try-it tool with FF3.5), I can't see any effect. Hence my question: what does this attribute really do?

EDIT It seems that it overrides the label used in the dropdown list. The contents of the option are (as far as I know) only used as the default for the value. Does this (in IE7+) make the following two declarations equivalent?

<option label="Volvo">Volvo (Latin for 'I roll')</option>

<option label="Volvo" value="Volvo (Latin for 'I roll')">Whatever....</option>


The label attribute defines a shorter version of the text which will appear for its option in the drop-down list of the select menu.

label is defined as an optional attribute of the option tag, meaning implementation of and support for the attribute is not required to be compliant with the W3C standard. More information can be found here about the option tag:

http://www.w3schools.com/tags/att_option_label.asp

And, here is the link to the W3C specification:

http://www.w3.org/TR/html4/interact/forms.html#edef-OPTION


(Edit):
@Martijn the only usefulness I see is that it allows the developer to define an option tag and the label sets the "viewable text", and close it shorthand, rather than having to also specify a separate closing option tag. This would result in less code/data sent to the browser/device, which might have implications in mobile applications.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK