JavaScript DHTML/Node Operation/appendChild

Материал из Web эксперт
Перейти к: навигация, поиск

"appendChild()" Example

 
    
<html>
<body>
<script language="javascript">
function function1(){
   var myElement = document.createElement("<div style="width:600; height:200;background-color:blue;"></div>");
   document.all.myBody.appendChild(myElement); 
} 
</script>
<body id="myBody"><button onclick="function1();">Append child</button></body>
</body>
</html>



Append text node to paragraph tag

 
<html>
<head>
    <title>Location</title>
    <script type = "text/javascript">
        function showProps() {
            var body = document.getElementsByTagName("body")[0];
            for (var prop in location) {
                var elem = document.createElement("p");
                var text = document.createTextNode(prop + ": " + location[prop]);
                elem.appendChild(text);
                body.appendChild(elem);
            }
        }
         
    </script>
</head>
<body onload="showProps()">
</body>
</html>