Axel Richter: Unterstützung für DOM Level ermitteln

Beitrag lesen

Hallo,

Ich dachte eigentlich das der IE6 und Opera 9.21 DOM Level 2 unterstützen, doch folgendes Beispiel beweist anscheinend das Gegenteil:

Der Schein trügt hier.

<select name="list" id="list" multiple>
   <option name="A" value="12">text A</option>
   <option name="B" value="14">text B</option>
   <option name="C" value="22">text C</option>
</select>

<script type="text/javascript">
   optionlist = document.getElementById("list").options;
   alert(optionlist.namedItem('B'));
</script>

Es wird NULL zurückgeliefert die Funktion namedItem exisitiert zwar hat aber keinen Rückgabewert. Im neusten Firefox funktioniert das einwandfrei.

Dann schlampt der Firefox hier.

Zitat aus http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#HTMLOptionsCollection-namedItem:
namedItem
This method retrieves a Node using a name. It first searches for a Node with a matching id attribute. If it doesn't find one, it then searches for a Node with a matching name attribute, _but only on those elements that are allowed a name attribute_.

Nach welcher HTML DTD darf das OPTION-Element ein Attribut "name" haben?

<select name="list" id="list" multiple>

<option id="A" value="12">text A</option>
    <option id="B" value="14">text B</option>
    <option id="C" value="22">text C</option>

</select>

<script type="text/javascript">
   optionlist = document.getElementById("list").options;
   alert(optionlist.namedItem('B'));
</script>

So funktioniert es auch im IE6.

viele Grüße

Axel