JavaScript Document Properties
Last updated: November 19, 2024
This is in the works! Would you like to help flesh it out? Let's do it!
Looks like we don’t have <dl>s styled!
Structural Properties
document.documentElement- The
<html>element, representing the root element of the document. document.body- The
<body>element of the document, where the main content resides. document.head- The
<head>element of the document, containing metadata, scripts, links to stylesheets, etc. document.title- The title of the document (the content inside the
<title>tag). document.forms- A collection (HTMLFormControlsCollection) of all
<form>elements in the document. document.images- A collection of all
<img>elements in the document. document.links- A collection of all
<a>and<area>elements with anhrefattribute. document.scripts- A collection of all
<script>elements in the document. document.embeds- A collection of all
<embed>elements in the document. document.plugins- Similar to
document.embeds, typically used for<embed>elements representing plugins (though rarely used today).
Metadata and Configuration
document.characterSet- The character encoding for the document (e.g., “UTF-8”).
document.contentType- The MIME type of the document (e.g., “text/html”).
document.URL- The full URL of the document.
document.domain- The domain name of the document (useful for security checks and same-origin policy).
document.referrer- The URL of the referring document (the page that linked to this document).
document.cookie- Allows reading and writing cookies associated with the document.
Document State and Navigation
document.readyState- The current loading state of the document (
loading,interactive, orcomplete). document.visibilityState- The visibility state of the document (
visible,hidden, etc.). document.lastModified- The date and time the document was last modified.
Window and Viewport
document.defaultView- The
windowobject associated with the document. document.scrollingElement- The element responsible for scrolling the document (
<html>or<body>, depending on the browser).
Selection and Focus
document.activeElement- The currently focused element in the document.
document.designMode- Toggles editing mode (
"on"or"off") for the entire document.
Miscellaneous Properties
document.doctype- The document type declaration (e.g.,
<!DOCTYPE html>), accessible as aDocumentTypeobject. document.implementation- Provides methods to create various document nodes like
DocumentTypeandDocumentFragment. document.children- A collection of the document’s child elements (usually just
<html>). document.nodeType- Always
9for a document node, identifying it as aDocumentobject. document.nodeName- Always
"#document"for aDocumentobject. document.inputEncoding- Similar to
characterSet, represents the character encoding.