[whatwg] getElementById

Perry Smith pedzsan at gmail.com
Mon May 10 14:27:07 PDT 2010


On May 10, 2010, at 3:06 PM, timeless wrote:

> On Mon, May 10, 2010 at 9:10 PM, Perry Smith <pedzsan at gmail.com> wrote:
>> I see places that explicitly state that the same object is returned on some operations.  For example, the element.style has that clause.
>> 
>> I have not found in either html5 or the DOM documentation that is referenced an explicit statement to this effect for getElementById.
> 
> if someone changes the id value on the node you used to think about
> and assigns it to another node then it most certainly will not return
> the same node.

Yea, that is an interesting point.

I wonder also if I change the id for the node to 'dog' and then do getElementById('dog') if it will give me back the same javascript object with newAttr set.

I am not sure if I am making myself clear.  The question(s) boils down to, are these objects going to behave consistently as javascript objects.

There are different ways the browser could implement the mapping from DOM elements to javascript objects.

For example, the following code could fail and not give the alert box:

foo = getElementById('foo');
foo.newAttr = 1;
if (foo.newAttr)
  alert("hi");

The setting of newAttr could simply not work at all.  The browser could throw it away.  There is nothing I see that says that it must work.  I say this because there are particular methods and attributes defined.  No mention is made of other attributes.  They could do anything including throw an exception, silently fail, or randomly do something else.

I might have missed something obvious.

Perry





More information about the whatwg mailing list