Javascript DOM <UL> element create

Description

Javascript DOM <UL> element create

View in separate window

<!DOCTYPE html>

<html>
<body>
    <script type="text/javascript">
        let shoppingList = [// ww  w  .  j  a  v a  2s.  com
            "Eggs",
            "Milk",
            "Juice",
            "Diapers",
            "Bread"
        ];

        let ul = document.createElement("ul");
        
        for (let i = 0; i < shoppingList.length; i++) {
            ul.innerHTML = ul.innerHTML + "<li>" + shoppingList[i] + "</li>";
        }

        document.body.appendChild(ul);
    </script>
</body>
</html>



PreviousNext

Related