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

[whatwg] getElementsByIdPart

From: Ian Hickson <ian@hixie.ch>
Date: Sat, 21 Aug 2004 19:03:03 +0000 (UTC)
Message-ID: <Pine.LNX.4.61.0408211615010.20869@dhalsim.dreamhost.com>
On Sat, 24 Jul 2004 chriswa at comcast.net wrote:
>
> It would be nice if you can add an API to that permit you to get 
> elements based on part of the Id name.  This would permit you to create 
> classes of controls in JavaScript.

I've added a getElementsByClass() method to the Web Apps spec draft which 
is probably a more semantically correct solution:

   http://whatwg.org/specs/web-apps/current-work/#selecting


> For example ASP.NET labels the id of controls as 
> ControlOuter1_ControlInner1_element.  If use such an API I can obtain 
> all the elements of ControlOuter1 then all the elements of 
> ControlInner1.  Thus I can build a control heirarchy in JavaScript.

You could loop over all the elements and make their class attributes equal 
their ID attributes with underscores changed to spaces quite easily, which 
would then allow you to use the method mentioned above, as well as letting 
you use CSS and other class-based mechanisms.

Does this help, or do you really think a getElementByIdPart() method 
would be better? What worries me about such a method is that an element's 
ID is supposed to be unique and opaque, and such an API suggests that IDs 
have some sort of structure.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Saturday, 21 August 2004 12:03:03 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:36 UTC