W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2011

[whatwg] Option label, textContent and value

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Tue, 8 Mar 2011 16:22:02 +0200
Message-ID: <B9A66787B5644598B878E7C328A58C07@JukanPC>
Markus Ernst wrote:

> <select>
>   <option label="Label1">TextContent1</option>
>   <option label="Label2">TextContent2</option>
> </select>
> - IE 8, Opera 11 and Chrome 9 display "Label1" and "Label2"
> - Firefox 3.6 displays "TextContent1" and "TextContent2"
> Firefox's behavour seems to be contradictory to the spec, which gives
> the label attribute precedence.

This is a bug in Firefox. The label attribute is defined for <option> even 
in HTML 4.01, though its use has been limited - it was mainly introduced for 
use in nested menus, where an <option> is inside <optgroup>

> Furthermore, as I understand the above definitions, the spec does
> allow to specify label and value in one step in a select element:
> <select>
>   <option>This is value and label
> </select>

Yes, that has been the case since HTML 2.

> But not in a datalist, as the label is taken from the textContent
> rather than from the value of the option element:
> <datalist>
>   <option value="No label here">
>   <option label="No value here">
> </datalist>

I'm not sure I follow you here... The idea is that a <datalist> element has 
no text content, i.e. all information is in the attributes of its children. 
If you had some content in the <option> element, then it would be visible on 
browsers that do not understand the <datalist> markup.

Technically it's a bit more complicated:
"The contents of the [datalist] element represents fallback content for 
legacy user agents, intermixed with option elements that represent the 
predefined options. In the rendering, the datalist element represents 
nothing and it, along with its children, should be hidden."

So you _could_ use <option value="xxx">foobar</option> inside <datalist>, 
but "foobar" would be ignored by conforming browsers - it would only appear 
on older browsers, hopefully constituting part of well-designed fallback 

Yucca, http://www.cs.tut.fi/~jkorpela/ 
Received on Tuesday, 8 March 2011 06:22:02 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:31 UTC