The Document object represents the entire HTML document. It is the root node of the HTML document tree, and provides access to all elements and properties within the document.
Properties
document.title
: Returns the title of the document.document.URL
: Returns the URL of the document.document.body
: Returns the<body>
element of the document.document.head
: Returns the<head>
element of the document.document.documentElement
: Returns the<html>
element of the document.document.doctype
: Returns the<!DOCTYPE>
declaration of the document.document.domain
: Returns the domain of the document.
Methods
document.getElementById(id)
: Returns the element with the specified ID.
--- ------- - -------------------------------------
document.getElementsByClassName(className)
: Returns a collection of elements with the specified class name.
--- -------- - -------------------------------------------
document.getElementsByTagName(tagName)
: Returns a collection of elements with the specified tag name.
--- -------- - -------------------------------------
document.createElement(tagName)
: Creates a new element with the specified tag name.
--- ---------- - ------------------------------
document.createTextNode(text)
: Creates a new text node with the specified text content.
--- -------- - ------------------------------- ---------
document.querySelector(selector)
: Returns the first element that matches the specified CSS selector.
--- ------- - -----------------------------------
document.querySelectorAll(selector)
: Returns a collection of elements that match the specified CSS selector.
--- -------- - -----------------------------------------
Events
DOMContentLoaded
: Fired when the initial HTML document has been completely loaded and parsed.load
: Fired when all resources (images, stylesheets, scripts, etc.) have been loaded.click
: Fired when a mouse click is detected on an element.submit
: Fired when a form is submitted.
This is just a brief overview of the HTML DOM Document object. There are many more properties, methods, and events available for working with the document in JavaScript.