HOME

DHTML Tutorial
DHTML HOME
DHTML Intro
DHTML CSS
DHTML DOM
DHTML Events

DHTML Examples
DHTML Examples

DHTML DOM
DOM window
DOM navigator
DOM event
DOM collection
DOM document
DOM form
DOM input
DOM select
DOM option
DOM textarea
DOM table
DOM tablerow
DOM tablecell
DOM anchor
DOM image
DOM frameset
DOM frame
DOM iframe

DOM Examples
DOM Examples

Resources
DHTML Books
Download XMLSpy here
Please visit our sponsors !

DHTML Document Object Model

previous next

Examples

Note: Most of the DHTML examples require Internet Explorer 4.0 or higher.

Element access
How to access an element and change the style.

Attribute change
How to access an image element and change the "src" attribute.

innertext access
How to access and change the inner text of an element.


DOM

HTML 4.0 introduced the Document Object Model, which gives us access opportunity to every element in the document. It contains no functions or fancy layout tricks, it is more like a map of all the elements, and we use this map to access the elements.


How to access the elements

A scripting language is needed. JavaScript is the most browser compatible scripting language, so we use JavaScript. To make an element available for the DOM, the element must define the id attribute.

<html>
<body>
<h1 id="header">My header</h1>
<script type="text/javascript">
header.style.color="red"
</script>
</body>
</html>

The script changes the style of the header element, and produces this output.

My header



The DHTML Object Model

Object   Explanation
window methods
properties
The window object is the top object in the DHTML Object Model, and gives you information about the window and the frames.
document methods
properties
collections
The document object represents the HTML document, and gives you access to the HTML elements.
navigator properties The navigator object gives you information about the user's browser.
event properties
collections
The event object gives you information about events that occur.


previous next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



ASP Hosting
ASP.net Hosting
Web Hosting



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

Books Online

Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search