Skip to content
Search

JavaScript:Document

lastmod 2023-02-19created 2020-10-145 edits

The Document interface represents a web page loaded in the browser and serves as the entry point to the page content (the DOM tree). The DOM tree includes elements such as

<body>

and

<table>

along with many others. Document provides functionality globally, such as getting the page's URL or creating new elements in the document.

The Document interface describes the common properties and methods for any kind of document. Depending on the document's type (HTML, XML, SVG, etc.), a larger API is available. For example, HTML documents served with the "text/html" content type also implement the HTMLDocument interface, whereas XML and SVG documents implement the XMLDocument interface.

How to get browser URL properties

APIs

createElement

Creates a new element.

document.createElement('h1');

generates the following code.

<h1></h1>

The created element is added as a node using Node.appendChild() or Node.insertBefore().

createTextNode

document.createTextNode('My Text');

See also

Favorite site

author Zer0 sitemap