2006-10-16 23:52 UTC The DOM0 Legacy: HTMLOptionsElement
I'm trying to spec DOM5
HTML, a part of the same specification as HTML5/XHTML5. Specifically,
today I'm trying to specify the various collection interfaces, and in
particular, I'm trying to specify
HTMLOptionsCollection
.
The DOM2 HTML spec's take on the matter is somewhat far from the truth.
Here are some amusing tidbits I've found so far:
- In IE7, the select element is the same as its
options
collection. Literally, it's the same object. (Demo) - In IE7, the
namedItem()
method of theHTMLOptionsCollection
/HTMLSelectElement
object is not equivalent to indexing into the object using the JavaScript square-bracket notation. (Demo) - In Opera9,
HTMLOptionElement
s have alength
property that returns the number ofoption
elements in theirselect
element. I can't find any reason for this attribute's existence. No other browser does this. (Demo) - In Webkit trunk and IE7, if multiple elements match the argument
to
HTMLSelectElement.options.namedItem()
, then a list is returned, much like when (in any browser) multiple nodes matchHTMLFormElement.elements.namedItem()
. In Firefox trunk and Opera9, only a single element is returned, not a list, much like when (in any browser) multiple nodes matchHTMLDocument.images.namedItem()
. (The fact thatHTMLFormElement.elements
andHTMLDocument.images
are both, according to the DOM2 HTML spec, supposed to beHTMLCollection
objects with the exact same behaviour is, of course, neither here nor there.) (Demo) - In Webkit trunk and Firefox trunk,
id
andname
attributes onoption
elements are considered equals when it comes to matching fornamedItem()
. In Opera9 and IE7, only theid
attribute is examined, thename
attribute is ignored. (Demo) - In Webkit trunk, setting the
length
property to a smaller value doesn't remove children ofoptgroup
elements. (Demo) - In IE7, setting the
length
property to a greater value adds new nodes to the lastoptgroup
element of theselect
, if there are nooption
nodes after it. (Otherwise, it does like other browsers, and append them to theselect
.) (Demo)
The spec is going to be a mix of all of the above, so none of the browsers are going to exactly match it.