getElementsByClassName

getelementsbyclassname.js

Inspired by the post and comments at http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/

Example Markup:

<p id="p1" class="aaa bbb">

<p id="p2" class="aaa ccc">

<p id="p3" class="bbb ccc">

<p id="p4" class="aaa aaa-bbb ccc">

Try it out:

Skinny on the code:

var matches = getElementsByClassName(node, cls, [tag])

node
root node - where to begin search
cls
array or space delimited string of classnames
tag
optional tagname used to limit search to specific elements

Curtis Harvey website | email