DHTML - HTML DOM
The following example changes the content of an h1 element:
Change an HTML Element Example
<html>
<body>
<h1 id="header">Old Header</h1>
<script type="text/javascript">
document.getElementById("header").innerHTML="New Header";
</script>
</body>
</html>
Example explained:
- The HTML document above contains an h1 element with id="header"
- We use the HTML DOM to get the element with id="header"
- A JavaScript changes the content (innerHTML) of that element
The following example changes the src attibute of an img element:
Change an HTML Attribute Example
<html>
<body>
<img id="image" src="smiley.gif">
<script type="text/javascript">
document.getElementById("image").src="landscape.jpg";
</script>
</body>
</html>