// gets the element with an id of "MG"
document.getlElementById("Mg").value;
// returns all the div elements as an array
document.getElementsByTagName("div");
// returns the first one of the elements in the array
document.getElementsByTagName("p")[0];
// The root element in HTML ...
document.documentElement;
// Creates a new
object
document.createElement("img");
// 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. In other words, avoid using it.
*/
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/PacB5y-XUP0/13483