[whatwg] getElementsByClassName() idea

Lachlan Hunt lachlan.hunt at lachy.id.au
Sun Nov 5 02:54:06 PST 2006


Anne van Kesteren wrote:
> I think this hasn't been suggested before. Perhaps the method should 
> accept a DOMTokenString as argument instead of an array. This allows 
> things like ele.getElementsByClassName(ele.className) etc.

Since a DOMTokenString just extends DOMString, anything that accepts a 
DOMString will automatically be able to accept a DOMTokenString, 
including getElementsByClassName.  So your example will already work. 
Conversely, if it were defined as accepting a DOMTokenString, you 
couldn't pass it a regular string.

> The only problem is how to get a DOMTokenString without first getting 
> className from somewhere. Perhaps it should be a constructor as well. 
> 'x = new DOMTokenString("aaa bbb")'

That might be useful.  Though, I can't think of any specific use cases 
for needing it other than for class names.

-- 
Lachlan Hunt
http://lachy.id.au/



More information about the whatwg mailing list