W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2010

[whatwg] getElementById

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 3 Aug 2010 21:56:36 +0000 (UTC)
Message-ID: <Pine.LNX.4.64.1008032152180.7470@ps20323.dreamhostps.com>
On Mon, 10 May 2010, Perry Smith 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.

getElementById() is a DOM Core method, so not defined by the HTML spec.

However, the DOM spec says it returns "the Element", so that seems to 
require that the same Element object representing the element be returned.
In practice there is always only one object per element anyway.


> The other part to this that is not explicitly mentioned is if I attach a 
> new javascript attribute to the object, is that legal?  Is it defined to 
> work?  I have not found a statement one way or the other.
> 
> e.g.
> 
> foo = getElementById('foo');
> foo.newAttr = true;
> 
> /* later */
> 
> foo = getElementById('foo');
> if (foo.newAttr) {
>   alert("happy happy joy joy");
> }

This would be defined by WebIDL.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 3 August 2010 14:56:36 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:25 UTC