Visit Mozilla.org

DOM:document.firstChild

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Returns the first node in the list of direct children of the Document.

Note: The returned node is not necessarily the root element of the document; it can also be a processing instruction, for example. If you need the root element, use document.documentElement.

[edit] Syntax

var child = document.firstChild 
  • child is the returned Node.

[edit] Example

Suppose we have an HTML document. The following statement will alert [object DocumentType] if the document has a DTD, or [object HTMLHtmlElement] if the first node is <html>:

alert(document.firstChild);

[edit] Specification

DOM Level 2 Core: Node.firstChild