Prototype - 兄弟節點()方法



此方法會收集元素的所有兄弟節點並作為擴充套件元素陣列返回。

如果元素具有相同的父元素,則這兩個元素是兄弟節點。例如,頭部元素和 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">Click the button to see the result.</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.htm
廣告
© . All rights reserved.