DOM bug in getElementById()

  • Thread starter Thread starter shanti
  • Start date Start date
S

shanti

In Internet Explorer 6, getElementById() can return a form field whose
name (but not id) matches the search. This is erroneous -- an id is
unique in a document, a name is not.

In this example, click on the button. The text "foo bar" should change
to "hello, world". Mozilla executes this document correctly. In IE, the
texatrea changes instead.

<html>
<body>
<form>
<textarea name=choices rows=10 cols=40>
ABCDE
</textarea>
</form>

<script>
var choices = ['1','2','3','4',5];

function test()
{
var x = document.getElementById("choices");
alert(x.innerHTML);
x.innerHTML="hello, world";
}

</script>

<span id=choices>foo bar</span>

<input type=button onClick="test()" value="Test">
</body>
</html>
 
In Internet Explorer 6, getElementById() can return a form field whose
name (but not id) matches the search. This is erroneous -- an id is
unique in a document, a name is not.

This is known behaviour. Known certainly by many Web developers. IE has
many irregularities when it comes to the W3C DOM, with some even implied
by MSDN documentation as conforming. I doubt this will change any time
soon, unfortunately.

[snip]

By the way, when presenting test cases, it's best to ensure that the
case validates and fully conforms to the relevant standards. Though IE
will happily parse tag soup, at least a valid example will lay blame
squarely with the user agent.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top