Tuesday, August 25, 2015

Common Document object model traversing

document.createElement() Creates an Element node
document.createTextNode() Creates a Text node

element.appendChild("new node") Adds a new child node, to an element, as the last child node
element.insertBefore("new node", "Which node before") Inserts a new child node before a specified, existing, child node

element.removeChild("existing node") Removes a child node from an element
element.replaceChild("new node", "Which existing node will be replace") Replaces a child node in an element

to learn more: http://www.w3schools.com/jsref/dom_obj_document.asp

Dom Traversing
================================================
element.parentNode Returns the parent node of an element
element.parentElement Returns the parent element node of an element

element.childNodes Returns a collection of an elements child nodes (including text and comment nodes)
element.childNodes[i] Returns an element child nodes (including text and comment nodes)


element.firstChild Returns the first child node of an element
element.firstElementChild Returns the first child element of an element

element.lastChild Returns the last child node of an element
element.lastElementChild Returns the last child element of an element

element.nextSibling Returns the next node at the same node tree level
element.nextElementSibling Returns the next element at the same node tree level

element.previousSibling Returns the previous node at the same node tree level
element.previousElementSibling Returns the previous element at the same node tree level

to learn more: http://www.w3schools.com/jsref/dom_obj_all.asp



No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }