Prototype - nextSiblings() 方法



此方法收集元素的所有後代兄弟元素,並將它們作為一個擴充套件元素陣列返回。

注意 - 如果兩個元素有相同的父元素,那麼它們就是兄弟元素。

語法

element.nextSiblings();

返回值

一個 HTML 元素陣列。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var str = $('mutsu').nextSiblings();
            alert( "$('mutsu').nextSiblings() " + str[0].innerHTML );
            alert( "$('mutsu').nextSiblings() " + str[1].innerHTML );
   
            var str = $('ida-red').nextSiblings();
            alert( "$('ida-red').nextSiblings() " + str[0] );  
         }
      </script>
   </head>

   <body>
      <p>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>
      <br />
      
      <input type = "button" value = "Click" onclick = "showResult();"/>
   </body>
</html>

輸出

prototype_element_object.htm
廣告
© . All rights reserved.