Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Prototype adjacent() Method


previous next AddThis Social Bookmark Button


This method finds all siblings of the current element that match the given selector(s) and returns them as an array.

Syntax:

element.adjacent([ selectors...]);

Return Value:

  • An array of HTML elements.

Example:

<html>
<head>
<title>Prototype examples</title>
<script type="text/javascript" 
   src="/javascript/prototype.js">
</script>
<script>

function listCities(){
   var arr = $('nyc').adjacent('li.us');

   arr.each(function(node){
      alert(node.nodeName + ': ' + node.innerHTML);
   });

}

</script>
</head>

<body>
   <ul id="cities">
    <li class="us" id="nyc">New York</li>
    <li class="uk" id="lon">London</li>
    <li class="us" id="chi">Chicago</li>
    <li class="jp" id="tok">Tokyo</li>
    <li class="us" id="la">Los Angeles</li>
    <li class="us" id="aus">Austin</li>
  </ul>

   <br />
   <input type="button" value="List Cities" 
             onclick="listCities();"/>
</body>
</html>

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



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names