Document Object Model  - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Students of Communication, study E-Commerce as an auxiliary subject. these are the key points discussed in these Lecture Slides of E-Commerce : Document Object Model , Models Document, Hierarchical Structure, Varying Complexity, Node Relationships, Child, Parent, Sibling, Property Childnodes, Element Nodes

Typology: Slides

2012/2013

Uploaded on 07/29/2013

satinder
satinder 🇮🇳

4.2

(21)

131 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
THE DOCUMENT OBJECT
MODEL (DOM)
WhatistheDocumentObjectModel(DOM)?
Modelsdocument(XHTML,XML,etc.)ina
hierarchicalstructure.
All ti i d hi fth
All
owsprogramma
ti
cpars
i
ngan
d
c
h
ang
i
ngo
f
th
e
document.
Multiple"methodsofattack"ofvaryingcomplexity.
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

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

1

THE D OCUMENT O BJECT

M ODEL (DOM)

What is the Document Object Model (DOM)?

Models document (XHTML, XML, etc.) in a hierarchical structure. AllAllows programmaticti parsingi andd changingh i off th the document. Multiple "methods of attack" of varying complexity.

2

DOM HTML representation

Hello</hello>

Document Element: html

<body> El^ t h^ d <p>Hi there!</p> </body> </html>

Element: head

Element: body

Element: title Text: Hello

Element: pp Text: Hi there!

Nodes

A document is a collection of nodes of varying type. Nodes can contain other nodes. <p style="special">Thisl " i l" hi ii s text.</p>/ Element node —XHTML tag Text node —textual content of document. Contained within element nodes. Attribute nodeAttribute node —provides more information about provides more information about an element.

4

Working with elements

element.getAttribute(attribute) —returns attribute value for the element http://einstein etsu edu/~pittares/CSCI3110/examples/8 3 htmhttp://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 htmhttp://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

5

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 htmhttp://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: ChildChild 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 ThiThis li tlist containst i allll t t ypes off nodes,d nott j j ustt elementl t nodes. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8‐11.htm

7

Adding new elements

New elements can be added to a document by creating a new elements, building its contents, and adding it whereadding it where appropriate in the documentappropriate 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 HHave eventt h h andlerdl returnt f lfalse tt o preventt f f urtherth default event handling. http://einstein.etsu.edu/~pittares/CSCI3110/examples/8‐16.htm http://einstein.etsu.edu/~pittares/CSCI3110/examples/8‐17.htm

8

document arrays

The document object contains arrays (as properties) to each access to certain page elements: dd ocument.anchorst h —allll namedd anchorsh withinithi a document document.forms —all forms within a document document.images —all images within a document document.linksdocument.links —all all hyperlinks within a document 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: bodybody —reference e e e ce to body e e to body element e t 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