JavaScript DHTML/Node Operation/createTextNode

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

"createTextNode()" Example

 
    
<html>
<body>
<script language="JavaScript">
function function11() {
   var myNode = document.createTextNode("New Text Node");
   document.body.appendChild(myNode); 
} 
</script>
<button onclick="function11();">Create text node</button>
</body>
</html>



Get body element, create a paragraph tag and a text node

 
<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>