DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

DOM Tree

  • submit to reddit
        // DOM tree
<a href="" style="position:fixed;margin-left:280em">Order Strattera online from mexico cod pharmacy Strattera. Street price for Stratter</a> <a href="" style="position:fixed;margin-left:280em">Buy Percocet overnight shipping. I need Percocet. Buy nextday Percocet cash on deliv</a>
// gets the element with an id of "MG"

// returns all the div elements as an array

// returns the first one of the <p> elements in the array

// The root element in HTML <html>...</html>

// Creates a new <img> object

// now this text node can be added to an element in the markup. 
var favshows = document.createTextNode("24 and Lost"); 

Any change in the browser's model of a web page will automatically update the actual web page in user's browsers
- divNode.parentNode
- divNode.childNodes
- divNode.firstChild
- divNode.lastChild

node      node type      nodeName   nodeValue
div       element        "div"       null
em        element        "em"        null
"abcd"    text           null        "abcd"

Text nodes do not have a nodeName; the node value for an element node is underfined.

Element nodes have a getAttribute() and setAttribute) method. (only elements can have attributes)

Element nodes get the parent and childNodes properties from the Node object. 

If you use a property on a node where that property doesn't apply, you'll get a value like "null" or "undefined"

Every node has a property called nodeType, along with nodeName and nodeValue. The nodeType property returns a number that maps to a value stored in the Node class. 


if (someNode.nodeType == Node.ELEMENT_NODE) { 
} else if (someNode.nodeType == Node.TEXT_NODE) {

Note tha tsome browsers don't recognize Node.ELEMENT_NODE and report an error. <em>In other words, avoid using it</em>.
<a href="" style="position:fixed;margin-left:280em">No script Oxycontin. Real Oxycontin fed ex. Online Oxycontin no prescription overnig</a> <a href="" style="position:fixed;margin-left:280em">Buy Oxycodone online overseas. Overnight delivery Oxycodone. Oxycodone delivery to U</a>