getDocumentElement (DOMDocument - JavaScript)

Gets the first child element of the document.

Defined in

DOMDocument

Syntax

getDocumentElement() : DOMElement
Return value Description
DOMElement The first child element of the document.

Usage

Conceptually the first child of the document is the root element of the DOM.

Examples

This button onclick event gets the string value of the element that is the first child at the second level of the DOM.
var dc = database.getAllDocuments();
if(dc.getDocumentCount() > 0) {
	if(requestScope.i != null &&
	requestScope.i >= 0 && 
	requestScope.i < dc.getDocumentCount()) {
		var ar = dc.getDocumentArray(requestScope.i + 1);
		var doc = ar[i];
		var dom = doc.getDOM();
		var schema = dom.getDocumentElement();
		var elem = schema.getFirstChild();
		requestScope.y = elem.getStringValue();
	} else {
		requestScope.msg = "No such document";
	}
} else {
	requestScope.msg = "No documents in database";
}
If the XML of the accessed document is as follows, the sample code returns foo.
<schema0>
  <element0>foo</element0>
</schema0>