DHTML Document Object Model
The Document Object Model gives us access
to every element in a
document.
Examples
Note: Most of the DHTML examples require IE 4.0+, Netscape 7+, or Opera 7+!
Element access
How to access an element and change the style.
Attribute change
How to access an image element and change the "src" attribute.
innerHTML
How to access and change the innerHTML of an element.
How to access an element?
The element must have an id attribute defined and a scripting language is
needed. JavaScript is the most browser compatible scripting language, 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> |
The script changes the color of the header element, and produces this output.
 |
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
|
|