Java Reference
In-Depth Information
Properties of the Node Object
Description of Property
ownerDocument
Returns the root node of the document that contains the node
(note this is not available in IE 5 or 5.5)
parentNode
Returns the element that contains the current node in the tree
structure
nodeName
Returns the name of the node
nodeType
Returns the type of the node as a number
nodeValue
Gets or sets the value of the node in plain text format
Let's take a quick look at how some of these properties work. Consider this familiar example:
<!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 h1Element = document.getElementById(“heading1”);
h1Element.style.color = “red”;
</script>
</body>
</html>
You can now use h1Element to navigate your tree structure and make whatever changes you desire. The
following code uses h1Element as a starting point to fi nd the <p/> element and change its text color:
<!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 h1Element = document.getElementById(“heading1”);
h1Element.style.color = “red”;
var pElement;
if (h1Element.nextSibling.nodeType == 1)
{
Search WWH ::




Custom Search