document.getElementsByClassName
deprecated

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.

As of Prototype 1.6, document.getElementsByClassName has been deprecated since native implementations return a NodeList rather than an Array. Please use $$ or Element#select instead.

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)