[thelist] IE javascript question

Lee Kowalkowski lee.kowalkowski at googlemail.com
Mon Jul 2 16:42:11 CDT 2007

On 02/07/07, Jeffrey Barke <jeffrey.barke at themechanism.com> wrote:
> Lee,
> >>> <div id="EX_AATD" class="hiding"><label> <input type="checkbox"
> >>> name="EX_AATD">Item 1</label></div>
> >> The div has the same id as the checkbox has name. This is bad,
> >> because IE returns an element with a name attribute that is equal to
> >> the id specified.
> >
> > Not when using getElement(s)By* it doesn't...
> Possibly I wasn't clear and maybe I'm misunderstanding you, but
> document.getElementById may return an element with a name attribute
> equal to the id specified in IE and Opera.

Oops, that was my wrong choice of words.  I meant in this instance
it's not doing that (because the desired element appears first in the
HTML source).  What I actually said was wrong, 'my bad'.

I was also trying to say something else at the same time about the
getElement DOM accessors being more reliable than the DOM tree
traversal properties (which I managed to get right afterwards), I
didn't say it very well, but I did seem to imply there's a different
way of getting it wrong (which there is, going
document.formName.fieldName will be tripped up by the same naming

It's just because in IE name and id seemingly synonymous, possibly
because of the several places in the HTML specification where id and
name attributes blend a little:
  Name and id on anchor elements share the same namespace (if both are
supplied, they must be the same)
  The name attribute on the form and image element is only included
for backwards compatability, id should be used instead.
  Under the changes section: "The id and class attribute allow authors
to assign name and class information to elements".
  There's a very interesting paragraph at the end of 18.2.2:

The DOM specification is much clearer (but this only really comes into
play once the HTML has been parsed).  However, like you said, it's not
good practice to have clashing name and id attribute values.


More information about the thelist mailing list