getElementsByClassName :: Element

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.

 

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');

// -> []

 


Prototype API 1.5.0 - prototypejs.org