Docsity

Document Methods - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
1
CSCI 3110 Advanced Topics in Web Development
THE DOCUMENT OBJECT
MODEL (DOM)
What is the Document Object Model (DOM)?
Models document (XHTML, XML, etc.) in a
hierarchical structure.
Allows programmatic parsing and changing of the
document.
Multiple "methods of attack" of varying complexity.
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Document Methods - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

CSCI 3110 Advanced Topics in Web Development

THE DOCUMENT OBJECT

MODEL (DOM)

What is the Document Object Model (DOM)?

Models document (XHTML, XML, etc.) in a hierarchical structure. Allows programmatic parsing and changing of the document. Multiple "methods of attack" of varying complexity. Docsity.com

Nodes

A document is a collection of nodes of varying type. Nodes can contain other nodes.

This is text.

**Element node** —XHTML tag **Text node** —textual content of document. Contained within element nodes. **Attribute node** —provides more information about an element.

DOM HTML representation

Hello

Hi there!

Document Element: html Element: head Element: body Element: title Text: Hello Element: p Text: Hi there! Docsity.com

Working with elements

element.getAttribute(attribute) —returns attribute value for the element http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-3.htm element.setAttribute(attribute, value) —sets/resets the attribute value for the element http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-4.htm http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-5.htm http://webbugtrack.blogspot.com/2007/08/bug- 242 - setattribute-doesnt-always-work.html

Working with elements

An element node's text can be read and modified using the innerHTML property. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-6.htm innerHTML sees/sets the entire contents of the specified element, including other embedded tags/elements. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-7.htm Docsity.com

Working with elements

In the context of DOM, an element is an object. It may or may not have a toString method defined. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-8.htm http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-9.htm

Node relationships

All nodes in a document are related. Relationship types: Child Parent Sibling Each node has a property childNodes which contain an array-like list of children. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-10.htm This list contains all types of nodes, not just element nodes. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-11.htm Docsity.com

Adding new elements

New elements can be added to a document by creating a new elements, building its contents, and adding it where appropriate in the document hierarchy. element .appendChild(element) http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-15.htm

Events

DOM events can be added to elements: http://en.wikipedia.org/wiki/DOM_events Have event handler return false to prevent further default event handling. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-16.htm http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-17.htm Docsity.com

document arrays

The document object contains arrays (as properties) to each access to certain page elements: document.anchors —all named anchors within a document document.forms —all forms within a document document.images —all images within a document document.links —all hyperlinks within a document http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-18.htm

document properties

The document object contains properties to each access to certain page elements: body —reference to body element cookie —sets/reads cookies associated with document domain —domain name for current document lastModified —date/time document last modified referrer —URL that referred to current document title —title of current document URL —URL of current document http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-19.htm http://einstein.etsu.edu/~pittares/CSCI3110/examples/8-20.htm Docsity.com