Several getElementsByClassName() prototype methods in about 140 bytes (more or less). Useful for Internet Explorer <9.0 and (few) other old web browsers that do not support HTML5. Done for 140byt.es.
All "full" versions perfectly match the W3C specification, as far as I know. They support multiple class names in every order and class names that start with or contain dashes or nonascii characters.
The short version (138 bytes) does not support searching for multiple class names and fails when the query string contains any whitespace character.
The "annotated" version is a compromise with a few restrictions (see the comment below). It supports searching for multiple class names and should work in most web browsers.
Oh, moving the
RegExp(...)
part into the loop wherea
is used saves 4 bytes. 2 bytes by moving theb=...
into the for loop. 2 more by replacingif()
with&&
. 22 to go. A not so nice trick would be to split this intoand call the inner function 131 bytes (other 140byt.es snippets do similar by not counting essential strings or arrays) but I don't feel comfortable with this. I want a full replacement, including the possibility to search for multiple class names in any order. Looking for single class names only is possible in 137 bytes: