DOM specifics

703 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
703
On SlideShare
0
From Embeds
0
Number of Embeds
188
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

DOM specifics

  1. 1. DOM Specifics<br />CIS-189<br />9/29/2009<br />
  2. 2. DocumentElement: provides access to root element<br />References an Element Node<br />In XHTML will refer to <html> element<br />CreateElement(tagName): Create a new element node with given tag name<br />Creating an element doesn’t add it to document, must be appended:<br />oDoc.documentElement.appendChild(oDoc.createElement(“Tests”))<br />Document InterfaceCommon Members<br />Note:“oDoc” is a document object<br />9/29/2009<br />
  3. 3. CreateTextNode(value): Create a text node using the argument as the specified value<br />oElement = oDoc.createElement(“DueDate”)<br />oElement.appendChild(oDoc.createTextNode(“10/5/2009”)<br />oDoc.documentElement.appendChild(oElement)<br />Creates an element node with the text node having specific date<br />Document InterfaceCommon Members – 2<br />9/29/2009<br />
  4. 4. CreateAttribute(attributeName): Create an attribute with specified name<br />oAttrib = oDoc.CreateAttribute(“Sequence”)<br />oAttrib.Value = “2”<br />Create attribute Sequence with value = 2<br />GetElementsByTagName(tagName): Returns all elements with specified name as a NodeList (similar to an array or collection)<br />varProjectNodes = oDoc.getElementsByTagName(“Project”)<br />Get all project nodes<br />Document InterfaceCommon Members - 3<br />9/29/2009<br />
  5. 5. Properties<br />Attributes<br />Parent Node<br />Child Nodes<br />First Child<br />Last Child<br />Previous Sibling<br />Next Sibling<br />Node Name<br />Node Type<br />Methods<br />HasChildNodes()<br />AppendChild()<br />CloneNode()<br />InsertBefore()<br />RemoveChild()<br />ReplaceChild()<br />Node InterfaceCommon Members<br />9/29/2009<br />
  6. 6. Attributes returns a namedNodeMap that contains all attributes of an Element node<br />oDoc.getElementsByTagName(“Assignment”)[0].Attributes<br />Get Attributes of first assignment element<br />ParentNode provides access to node that “owns” current node<br />oDoc.getElementsByTagName(“Assignment”)[0].parentNode<br />Get parent of first Assignment element<br />ChildNodes returns children of current node<br />oDoc.getElementsByTagName(“Project”)[0].childNodes<br />Returns list of nodes found in first projects node<br />Node Interface Examples<br />9/29/2009<br />

×