[whatwg] getElementsByClassName

Simon Pieters zcorpan at gmail.com
Fri Jul 6 07:07:29 PDT 2007


getElementsByClassName is defined to take an array of strings as argument.  
What exactly is an array? A native ECMAScript array, or anything with a  
'length' property and the properties '0' -> length-1? Is a DOMTokenList an  
"array" that can be passed to gEBCN?

Firefox has implemented it as a space separated string as argument. This  
seems more practical for the simple case and you can still pass an  
element's .className as argument (if DOMTokenList.toString is defined to  
return a string with the tokens being space separated, .classList can be  
passed as argument too). I don't think that the argument of being able to  
use classes containing spaces is relevant since no Web technology I know  
of can have classes containing spaces. I think that the argument of  
authors not understanding that the order doesn't matter applies equally  
much to CSS .foo.bar vs .bar.foo. For these reasons, I think the spec  
should use space separated string as argument instead of array (and  
perhaps define DOMTokenList.toString to be useful).


Finally, an editorial comment, the example uses both string as argument  
and array as argument. This might be confusing unless both are accepted.

-- 
Simon Pieters



More information about the whatwg mailing list