Create Element, Remove Child
The Document Tree Document Element Root Element Element Element Element Element Text: HelloWorld Attribute “href”
Dynamic HTML JavaScript can change all HTML elements dynamically Can change all the HTML attributes Can change all the CSS styles Can remover exiting HTML elements and attributes Can add new HTML elements and attributes Can react to all existing HTML events Can Create new HTML events
Node Object Element Node,, Document Node Node Text Node data
Node Object Some nodes of the tree are JavaScript objects corresponding to HTML elements.,, elements Element node Other nodes may contain text representing the content of an element. Text node There is a node representing the document. Document node
Properties of Node nodeType: Number representing the type of node(Element) nodeName: string providing a name of this Node Type. parentNode: reference to object that is this node’s parent. childNodes: reference to nodes that are this node’s child. previousSibling: previous sibling of this node. nextSibling: next sibling of this node. attributes: an array containing Attr instances representing this node’s attributes.
Node type ValueSymbolic ConstantNode Type 1Node.ELEMETN_NODEElement 2Node.ATTRIBUTE_NODEAttribute 3Node.TEXT_NODEText 8Node.COMMENT_NODEComment 9Node.DOCUMENT_NODEDocument 10Node.DOCUMENT_TYPE_NODEDocumentType
Document Node Document Node is the parent of the html Element node. Properties of the document object title, body, url, etc Methods of the document object createElement(string): given an element type name (such as div), returns an Element instance corresponding to that element type. createTextNode(string): return a Text instance containing the given string as its data value. getElementById(string). getElementsByTagName(string).
Element Node Element node represents HTML elements.,,, etc Important methods of Element nodes. getAttribute(String) setAttribute(String, String) removeAttribute(String) hasAttribute(String)
Text Node Instances of the text DOM object are used to represent character data. The primary property of Text node is data, which is the text represented by the Text node. One Element node may have several Text nodes that are siblings of a single Text node.