Forum Moderators: open
<span id="parent_id"><input type="whatever" id="foobar"></span>
And then proceeded to try and remove the input element from my document:
parent = document.getElementById('parent_id');
child = document.getElementById('foobar');
parent.removeChild(child);
And I went on my dandy way thinking that was all I had to do. In fact, it worked perfectly in Firefox. Surprisingly, though, both IE6 AND Opera 9.25 decided that the child element could not be found, and threw an exception. Very bothersome. I mean, all of my ids are unique, and foobar is most definitely a child of parent_id. So what's up?
Well, earlier in my html I had this:
<input type="whatever" name="foobar">
That is to say, this input element shared its NAME attribute with the other's ID attribute. Now maybe I haven't studied the JavaScript specs enough, but I really don't think this should have interfered with the above lines of JavaScript. It seems, however, that IE6 and Opera 9.25 think that a call to document.getElementById('foobar') returns this input element with name="foobar" instead of the correct input element with id="foobar". I was only able to fix this by changing the child id to something different than 'foobar' (or changing the name of the other input to something else).
So I write this as a documentation of an honest JavaScripter's troubles with retarded browser implementation of JavaScript.
Is this reproducible by anyone other than me?
Is this a known bug?
Or did I just screw up because I'm an idiot and never learned this 'feature'?
Thanks for reading this rant.
So when assigning unique ids, I carelessly chose the scheme I describe above, and get that crappy side-effect.