Java Reference
In-Depth Information
playing with attributes
trY it out
Open your text editor and type the following code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 9, Example 1</title>
</head>
<body>
<p id="paragraph1">This is some text.</p>
<script>
var pElement = document.getElementById("paragraph1");
pElement.setAttribute("align", "center");
alert(pElement.getAttribute("align"));
pElement.removeAttribute("align");
</script>
</body>
</html>
Save this as
ch9 _ example1.html
and open it in a browser. You'll see the text of the
<p/>
element in the
center of the screen and an
alert
box displaying the text
center
(Figure 9-6).
figure 9-6