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.
@snowlord, this is really cool. The following is a full replacement for
getElementsByClassName
in 72 bytes, including multiple classes in every order, classes that start with or contain dashes or nonascii characters, and proper handling of white space including tabs. To bad this is useful for IE8 only, as said.65 bytes if you are sure you don't use tabs in your selector or spaces at the end.
It's true, IE7 does not know
HTMLElement
(neither does IE8), but I can dodocument.getElementsByClassName = ...
. Not perfect, but still helpful.