Copyright ©

Prototype previousSiblings() Method

previous next


This method collects all of element's previous siblings and returns them as an array of extended elements.

Two elements are siblings if they have the same parent. So for example, the head and body elements are siblings (their parent is the html element). Previous siblings are simply the ones which precede element in the document.



Return Value:


<title>Prototype examples</title>

<script type="text/javascript" 

function showResult(){
   var arr = $('ida-red').previousSiblings();
      alert(node.nodeName + ': ' + node.innerHTML);




  <p>Click the button to see the result.</p>

  <ul id="fruits">

  <li id="apples">
    <h3 id="title">Apples</h3>
    <ul id="list-of-apples">
      <li id="golden-delicious">Golden Delicious</li>
      <li id="mutsu">Mutsu</li>
      <li id="mcintosh" class="yummy">McIntosh</li>
      <li id="ida-red" class="yummy">Ida Red</li>
    <p id="saying">An apple a day keeps the doctor away.</p>  


  <br />
  <input type="button" value="Show Result" onclick="showResult();"/>


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

previous next

Copyright ©