1 / 10

Lecture 13: The Document Tree

Lecture 13: The Document Tree. Create Element, Remove Child. The Document Tree. Document. Root Element <html>. Element <head>. Element <body>. Element <title>. Element <a>. Element <h1>. Text: HelloWorld. Attribute “ href ”. Dynamic HTML.

daire
Download Presentation

Lecture 13: The Document Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 13: The Document Tree Create Element, Remove Child

  2. The Document Tree Document Root Element <html> Element <head> Element <body> Element <title> Element <a> Element <h1> Text: HelloWorld Attribute “href”

  3. 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

  4. Node Object Node Document Node Element Node <body>,<div>, <p> Text Node data

  5. Node Object • Some nodes of the tree are JavaScript objects corresponding to HTML elements. • <body>, <a>, <p> 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

  6. 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.

  7. Node type

  8. 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).

  9. ElementNode • Element node represents HTML elements. • <a>, <p>, <body>, etc • Important methods of Element nodes. • getAttribute(String) • setAttribute(String, String) • removeAttribute(String) • hasAttribute(String)

  10. 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.

More Related