Java Reference
In-Depth Information
Getting the Element's Tag Name: The tagName Property
The sole property of the Element object is a reference to the tag name of the element: the tagName
property.
In the previous example, the variable container contained the <html/> element. Add the following
highlighted line, which makes use of the tagName property.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>example</title>
</head>
<body>
<h1 id=”heading1”>My Heading</h1>
<p id=”paragraph1”>This is some text in a paragraph</p>
<script type=”text/javascript”>
var container = document.documentElement;
alert(container.tagName);
</script>
</body>
</html>
This code will now return proof that your variable container holds the outermost element, and by
implication all other elements within it (see Figure 12-5).
Figure 12-5
Search WWH ::




Custom Search