getElementsByClassName
deprecated

getElementsByClassName(element, className) -> [HTMLElement...]

Fetches all of element’s descendants which have a CSS class of className and returns them as an array of extended elements.

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.

The returned array reflects the document order (e.g. an index of 0 refers to the topmost descendant of element with class className).

Examples


<ul id="fruits">
  <li id="apples">apples
    <ul>
      <li id="golden-delicious">Golden Delicious</li>
      <li id="mutsu" class="yummy">Mutsu</li>
      <li id="mcintosh" class="yummy">McIntosh</li>
      <li id="ida-red">Ida Red</li>
    </ul>
  </li>
  <li id="exotic" class="yummy">exotic fruits
    <ul>
      <li id="kiwi">kiwi</li>
      <li id="granadilla">granadilla</li>
    </ul>
  </li>
</ul>

$('fruits').getElementsByClassName('yummy');
// -> [li#mutsu, li#mcintosh, li#exotic]

$('exotic').getElementsByClassName('yummy');
// -> []