Prototype - siblings() 方法

此方法收集元素的所有兄弟元素并将它们作为扩展元素数组返回。

如果两个元素具有相同的父元素,则它们为兄弟元素。因此,例如,head 和 body 元素是兄弟元素(它们的父元素是 html 元素)。

语法

element.siblings();

返回值

返回 HTML 元素数组。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var arr = $('mutsu').siblings();
            arr.each(function(node) {
               alert(node.nodeName + ': ' + node.innerHTML);
            });
         }
      </script>
   </head>

   <body>
      <p id = "test">单击按钮查看结果。</p>
      
      <ul>
         <li id = "golden-delicious">Golden Delicious</li>
         <li id = "mutsu">Mutsu</li>
         <li id = "mcintosh">McIntosh</li>
         <li id = "ida-red">Ida Red</li>
      </ul>
      
      <input type = "button" value = "Click" onclick = "showResult();"/>
   </body>
</html>

输出

prototype_element_object.html