Prototype - childElements() Method


Advertisements


Collects all of the element's children and returns them as an array of extended elements.

An index of 0 refers to the topmost child of an element.

Syntax

element.childElements();

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 showElements() {
            var arr =  $('father').childElements();
            arr.each(function(node) {
               alert(node.nodeName + ': ' + node.innerHTML);
            });
         }
      </script>
   </head>

   <body>
      <div id = "father">
         <p id = "kid1">This is first paragraph</p>
         <p id = "kid2">This is second paragraph</p>
      </div>
      <br />
      
      <input type = "button" value = "showElements" onclick = "showElements();"/>
   </body>
</html>

Output


prototype_element_object.htm

Advertisements