Newbie question: Why getElementById?

N

Nisse Engström

Well, what about the situation where there is a formelement or a form,
or whatever with the name "redBook" and also an id="redBook" elsewhere?
I don't know how IE solves that (nor care).
It is simply better to be clear AND stick to the standards, and thus use
getElementById.

I tend to agree, but is it really better?

In IE, getElementById("redBook") returns the form
element, and so do older (bug compatible) versions of
Opera. Recent versions of Opera, and Firefox[1] return
the other element.

Better keep names and ids unique.


/Nisse


[1]: The one version I have installed.
 

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

Members online

No members online now.

Forum statistics

Threads
474,098
Messages
2,570,625
Members
47,236
Latest member
EverestNero

Latest Threads

Top