DOM Enlightenment Book

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>




























































<h4 style="border-top:1px solid #ADADAD;padding-top:20px;margin-top:20px;"><strong>&larr; Code Example from <a href="http://www.domenlightenment.com/" target="_blank">DOM Enlightenment Book</a> by <a href="http://www.codylindley.com" target="_blank">Cody Lindley</a></strong></h4>

<p>JavaScript code is executed on page load. Click the "Run" button in the top bar to re-run the JavaScript code. All <code>console.log()'s</code> are logged to the <a href="http://getfirebug.com/firebuglite" target="_blank">Firebug Lite</a> console below &darr;.</p>

JavaScript

var elementNode = document.createElement('div');
console.log(elementNode, elementNode.nodeType); //log <div> 1, and 1 indicates an element node
var elementNode_1 = document.createElement('h1');
console.log(elementNode_1, elementNode_1.nodeType);

var textNode = document.createTextNode('Hi');
console.log(textNode, textNode.nodeType); //logs Text {} 3, and 3 indicates a text node