170 likes | 323 Views
DHTML and DOM: Document Object Model. Web programming. We have seen: Client side programming Javascript. DHTML. Dynamic HTML Make web pages dynamic using client-side scripting Content and appearance can be altered in response to browser events Fast and efficient
E N D
Web programming • We have seen: • Client side programming • Javascript
DHTML • Dynamic HTML • Make web pages dynamic using client-side scripting • Content and appearance can be altered in response to browser events • Fast and efficient • Typically it uses Javascript
DHTML • Collection of server-side techniques to make pages dynamic
Standard • Javascript • CSS • DOM: document object model
DOM • Standard from W3C • API: application programming interface • Standard to manipulate HTML and XML documents supported by most browsers
DOM objects • Represent different aspects of the document: • Windows • Documents • Elements • Attributes • Texts • Events • Style sheets, etc.
DOM tree • In order to manipulate the HTML document, it is seen as a tree • A tree has nodes • Some nodes are parents, • Parents have children
DOM • It is possible to create, destroy, or change any node in the DOM tree using Javascript • This means that any part of the HTML document can be changed dynamically • Remember the styles are also part of the tree so the appearance of anything can be changed too
DOM standard • Is a recommendation from W3C (starting in 1997) • So all html agents can use the same standard object oriented interface to HTML and XML documents • But not everything has been standardized, so be careful with things that may be browser dependent
DOM API • Is the interface between the objects implemented by the browser and Javascript • Each browser may implement an object differently as long as the interface and the functionality comply with the standard
DOM node interface • The properties of a node include information about • Itself (e.g node type) • The related nodes: • Parent, siblings, children
DOM tree traversal • From any node it is possible to traverse the rest of the tree (i.e. move to other node trees)
DOM Objects • have data and methods
HTMLElement data • tagName - read only • style - style object. e.g. element.style.backgroundColor • innerHTML - read/write - represents HTML source code inside the element
HTMLElement methods • getAttribute(attrName) • setAttribute(attrName, value) • removeAttribute(attrName) • hasAttribute(attrName)
HTML input control elements (eg buttons) • Name and value • focus() - get input focus • blur() - lose input focus • select() - selects current textual content for editing or copying • click()