G
G
Gesper2011-07-08 15:17:34
JavaScript
Gesper, 2011-07-08 15:17:34

getElementById in IE9

Can anyone explain to me how this can even be?

alert(document.getElementById(' ordinance_law_coverage ').id);
gives me the string ordinance_law_coverage0 .

There is an element on the page with id "ordinance_law_coverage".
There is also an element with an id of "ordinance_law_coverage0" and a name attribute of "ordinance_law_coverage".

So it turns out that in IE9 getElementById can in some cases find an element by name instead of id?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
Gesper, 2011-07-08
@Gesper

Yep, found the answer. msdn.microsoft.com/en-us/library/ms536437 (v=vs.85).aspx
getElementById: Returns the first object with the specified ID or NAME.
This should have been figured out.

M
MT, 2011-07-08
@MTonly

What element do you have an attribute on nameand why?
In which X-UA-Compatible mode do you have IE9?

G
Gesper, 2011-07-08
@Gesper

In my particular case, the Name of the checkbox. It is accompanied by an input type=hidden element whose ID matches the checkbox name. hidden holds the value associated with the checkbox. It is not possible to change the scheme of this whole miracle at the moment (the project is old and large, legacy features and all that).
The same getElementById behavior appears in both IE7 and IE8. Apparently, the MC thinks this is normal behavior.

M
MT, 2011-07-08
@MTonly

Again:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question