Copyright ©

Prototype select() Method

previous next


This method takes an arbitrary number of CSS selectors (strings) and returns an array of extended descendants of element that match any of them.

This method is very similar to $$() but can be used within the context of one element, rather than the whole document. The supported CSS syntax is identical, so please refer to the $$() docs for details.


Return Value:


<title>Prototype examples</title>

<script type="text/javascript" 

function showResult()

   var arr = $('apples').select('[title="yummy!"]');
   // returns [h3, li#golden-delicious, li#mutsu]
      alert("First : " + node.nodeName + ': ' + node.innerHTML);

   arr = $('apples').select( 'p#saying', 'li[title="yummy!"]');
   // returns [li#golden-delicious, li#mutsu,  p#saying]
      alert("Second : " + node.nodeName + ': ' + node.innerHTML);

   arr = $('apples').select('[title="disgusting!"]');
   // returns []
      alert("Third : " + node.nodeName + ': ' + node.innerHTML);



  <p id="test">Click the button to see the result.</p>
  <ul id="fruits">
  <li id="apples">
    <h3 title="yummy!">Apples</h3>
    <ul id="list-of-apples">
      <li id="golden" title="yummy!" >Golden</li>
      <li id="mutsu" title="yummy!">Mutsu</li>
      <li id="mcintosh">McIntosh</li>
      <li id="ida-red">Ida Red</li>
    <p id="saying">An apple a day keeps the doctor away.</p>  

  <input type="button" value="Click" onclick="showResult();"/>


To understand it in better way you can Try it yourself.

previous next

Copyright ©