JS case six _1: add city

Related knowledge points: add to child nodes: document.appendClild ()
Creation of text nodes: document.createTextNode ()
Creation of element nodes: document.createElement ()

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script>
            window.onload = function() {
                document.getElementById("btn").onclick = function() {
                    //1.Get UL nodeVar ulEle = document.getElementById ("ulEle");//2, Chuang JianwenThis nodeVar textNode = document.createTextNode ("Gao Song");//3, create Li node< li> < /li>Var liEle = document.createElement ("Li");//4, adding text nodes to Li nodesLiEle.appendChild (textNode);//5, Li Li Festival.Point added to UL nodeUlEle.appendChild (liEle);}}</script>< /head>< body>< input type= "button" value= "add" id= "BTN" />< UL id= "ulEle" >< li> Shanghai < /li> < li> New Zealand < /li> < Li> Tokyo < /li> < li> Moscow < /li>< /ul>< /body>< /html>

Leave a Reply

Your email address will not be published. Required fields are marked *