A polyfill for HTML5's getElementsByClassName()
method. In only 126 bytes.
- IE < 5
- FF > 20
Uses deprecated document.all
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
My version (https://gist.github.com/atk/5764611) doesn't rely on document.all. Also, your version leaks the variable "n"; you can save some types if you use ~foo.indexOf(bar) instead of foo.indexOf(bar)>-1:
Also, if you use the RegExp approach of my version (which will not work on classnames that contain chars not allowed there anyway), you can save another 2 bytes: