1. 程式人生 > >3父節點和兄弟節點

3父節點和兄弟節點

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        #ul li{
            width: 150px;
            height: 50px;
            background: blue;
            list-style: none;
        }
    </style>
</head> <body> <ul id="ul"> <li>11</li> <li>22</li> <li>33</li> <li>44</li> <li>55</li> </ul> <script> /* parenNode: 查詢某個元素的父節點. */
var ul = document.getElementById("ul"); var alis = ul.children; //console.log(alis[0].innerHTML); console.log(alis[0].parentNode.parentNode.parentNode.parentNode.parentNode);
</script> </body> </html>

這裡寫圖片描述
這裡寫圖片描述