getElementsByClassName :: Utility Methods

document.getElementsByClassName(className[, element]) -> [HTMLElement...] Retrieves (and extends) all the elements that have a CSS class name of className. The optional element parameter specifies a parent element to search under.

Note that each returned element has been extended.

Example

HTML:

<body>

<div id="one" class="foo">Single class name</div>

<div id="two" class="foo bar thud">Multiple class names</div>

<ul id="list">

<li id="item_one" class="thud">List item 1</li>

<li>List item 2</li>

<li id="item_two" class="thud">List item 3</li>

</ul>

</body>

JavaScript:

document.getElementsByClassName('foo');

// -> [HTMLElement, HTMLElement] (div#one, div#two)

document.getElementsByClassName('thud');

// -> [HTMLElement, HTMLElement, HTMLElement] (div#two, li#item_one, li#item_two);

document.getElementsByClassName('thud', $('list'));

// -> [HTMLElement, HTMLElement] (li#item_one, li#item_two)

Prototype API 1.5.0 - prototypejs.org