Java Reference
In-Depth Information
document object that returns the outermost element of your document. In HTML, this should always be
the <html/> element. The property that returns this element is documentElement, as shown in the fol-
lowing table.
Property of the
Document Object
Description
documentElement
Returns a reference to the outermost element of the document (the root
element, for example <html/> )
You can use documentElement as follows. If you go back to the simple HTML page, you can transfer
your entire DOM into one variable like this:
<!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;
</script>
</body>
</html>
The variable container now contains the root element, which is <html/> . The documentElement
property returned a reference to this element in the form of an object, an Element object to be precise.
The Element object has its own set of properties and methods. If you want to use them, you can refer to
them by using the variable name, followed by the method or property name.
container.elementObjectProperty
Fortunately, the Element object has only one property.
The Element Object
The Element object is quite simple, especially compared to the Node object (which you'll be introduced
to later). It exposes only a handful of members (properties and methods).
Member Name
Description
tagName
Gets the element's tag name
getAttribute()
Gets the value of an attribute
setAttribute()
Sets an attribute with a specifi ed value
removeAttribute()
Removes a specifi c attribute and its value from the element
Search WWH ::




Custom Search