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
optionscollection. Literally, it's the same object. (Demo) - In IE7, the
namedItem()method of theHTMLOptionsCollection/HTMLSelectElementobject is not equivalent to indexing into the object using the JavaScript square-bracket notation. (Demo) - In Opera9,
HTMLOptionElements have alengthproperty that returns the number ofoptionelements in theirselectelement. 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.elementsandHTMLDocument.imagesare both, according to the DOM2 HTML spec, supposed to beHTMLCollectionobjects with the exact same behaviour is, of course, neither here nor there.) (Demo) - In Webkit trunk and Firefox trunk,
idandnameattributes onoptionelements are considered equals when it comes to matching fornamedItem(). In Opera9 and IE7, only theidattribute is examined, thenameattribute is ignored. (Demo) - In Webkit trunk, setting the
lengthproperty to a smaller value doesn't remove children ofoptgroupelements. (Demo) - In IE7, setting the
lengthproperty to a greater value adds new nodes to the lastoptgroupelement of theselect, if there are nooptionnodes 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.