DHTML DOM (Document Object Model)

DOM (Document Object Model) is our ability to access each element in a document.

Example

Note:Most DHTML examples require IE 4.0+、Netscape 7+ or Opera 7+!

Element Access
How to access an element and change its style.
Attribute Change
How to access an image element and modify the "src" attribute.
innerHTML
How to access and modify the content of an element.

How to access an element?

The element must have a defined id attribute and need a script language. JavaScript is the best compatible script language for browsers, so we use JavaScript.

<html>
<body>
<h1 id="header">My header</h1>
<script type="text/javascript">
document.getElementById('header').style.color="red"
</script>
</body>
</html>

This script can change the color of the title element and generate output.

My header