Saturday, April 7, 2007

DOM API

Query

Methods:
document.getElementById
document.getElementsByTagName - returns array

element.getAttribute(attrName);


Properties:
element.parentNode
element.nextSibling
element.childNodes (can text node have child node? no)
element.childNodes.firstChild == element.childNodes[0]
element.childNodes.lastChild == element.childNodes[element.childNodes.length - 1]

Create
document.createElement
document.createTextNode

element.setAttribute(attrName, attrValue);
element.innerHTML
element.appendChild
element.insertBefore


Test

Use some of the above API to implement element.insertAfter(newElement, targetElement)

No comments: