This is a common interview question used by google, I wrote up a fiddle to show how this can be done. This is probably more functionality than is expected by the interviewer but is a good reference.
Other Methods:
http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
jsfiddle code here