views:

682

answers:

1

I'm running into an odd failure. It seems that if I have both an ID and NAME attribute on an anchor element, document.getElementById fails. If I remove the NAME, it works. I'm seeing this in Firefox 3.5(latest) but haven't checked other browsers yet.

Is this a bug or intentional?

+4  A: 

I've never heard of such a bug, so I attempted to reproduce it and failed. This suggests that you have misdiagnosed the problem, or at least haven't provided enough information about it.

I tested with Firefox 3.5 and the following code.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;
<title>Test of getElementById with named anchors</title>
<h1>Test of getElementById with named anchors</h1>

<h2><a name="one" id="one">First section</a></h2>
<p>The quick brown fox</p>

<h2><a name="two" id="second">Second section</a></h2>
<p>The quick brown fox</p>

<script type="text/javascript">    
if (document.getElementById('one')) {
        document.write("<p>First section found - id matches name<\/p>");
}

if (document.getElementById('second')) {
        document.write("<p>Second section found - id does not match name<\/p>");
}
</script>
David Dorward
same, I could not reproduce it on my 3.5.2 firefox. :\
bLee
Thanks for testing guys. I've no idea what's causing it at the moment, but if I get some time in the future I will investigate. I want to know if its my code somehow, or an odd edge case that I haven't been able to fully describe.
Geuis