Java Reference
In-Depth Information
<head>
</head>
<body>
<h1 id="heading1">My Heading</h1>
<p id="paragraph1">This is some text in a paragraph.</p>
<script>
var h1Element = document.getElementById("heading1");
h1Element.style.color = "red";
</script>
</body>
</html>
figure 9-4
If you display this in the browser, you see that you can directly influence the attributes of the
<h1/>
element in script, as you have done here by changing its text color to red.
Note
The
style
object points to the style attribute of an element; it enables
you to change the CSS style assigned to an element. The
style
object is
covered later in the chapter.