Javascript DOM Element Traverse

Description

Javascript DOM Element Traverse

View in separate window


<html>
    <head>
        <title>My List</title>
    </head>

    <body>
        <h1 class="myHeading">My List!</h1>
        <ul id="myUnorderedList">
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
            <li>Item 4</li>
        </ul>
    <script>
    // Get the head and body elements
    let head = document.documentElement.childNodes[0];
    let body = document.documentElement.childNodes[1];
    //from  w  w  w . j a va 2  s . c  o  m
    // Get the list Object
    // NOTE: In W3C this will point to the H1 due to the whitespace
    let listObj = document.documentElement.childNodes[1].childNodes[1];
    
    </script>
    </body>
</html>



PreviousNext

Related