JAVASCRIPT

Document

The JavaScript Document object is the root node of the document tree in HTML, XHTML and XML documents.[](https://www.google.com/search?q=javascript+window.document “search?q=javascript+window.document”)

Properties

Anchor

The anchor object represents the HTMLAnchorElement.

// show the number of anchors in the document
alert(document.anchors.length);

BaseURI

The baseURI object is a string that represents the absolute base URL of a node. Not supported in Internet Explorer.

alert(node.baseURI);

Body

The body object represents the HTML body element.

// show the HTML within the body of the document
alert(document.body.innerHTML);

Cookie

The cookie object is a string that represents a semicolon-separated key/value pair list of cookies.

// show all cookies
alert(document.cookie);

Doctype

The doctype object represents the Document Type Declaration (DTD).

// show DTD name
alert(document.doctype.name);

DocumentElement

The documentElement object represents the root document element.

var rootElement = document.documentElement;

DocumentMode

The documentMode object is a floating point variant that represents the document compatibility mode. The documentMode property is only supported in Internet Explorer 8+.

// show document compatibility mode
alert(document.documentMode);

DocumentURI

The documentURI object is a string that represents the document location. Not supported in Internet Explorer.

var uriString = document.documentURI;

Domain

The domain object is a string that represents the document domain.

var domainString = document.domain;

Forms

The forms object is a HTMLCollection that represents the forms in the document.

var formsCollection = document.forms;

Images

The images object is a HTMLCollection that represents the images in the document.

var imagesCollection = document.images;

Implementation

The implementation object is a DOMImplementation associated with the document.

var domImplementation = document.implementation;

LastModified

The lastModified object is a string that represents the date and time the document was last modified.

// show last modified date and time
alert(document.lastModified);

Links

The links object is a collection that represents all area and anchor elements in the document with a href attribute value.

var linksCollection = document.links;

ReadyState

The readyState object is a string that represents the loading status of the document.

/*
readyState values:
uninitialized - loading not started
loading - is loading
interactive - loaded enough for user interaction
complete - fully loaded
*/
var loadingStatus = document.readyState;

Referrer

The referrer object is a string that represents the URI of the page that linked to the current document.

alert(document.referrer);

Title

The title object is a string that represents the title of the document.

alert(document.title);

URL

The URL object is a read-only string that represents the URL of the document.

alert(document.URL);

Methods

AdoptNode

The adoptNode method removes the node from the document it’s in and changes its ownerDocument to the current document.

var adoptedNode = document.adoptNode(externalNode);

Close

The close method ends writing to a document opened with document.open().

document.open();
document.write("<p>Hello world!</p>");
document.close();

CreateAttribute

The createAttribute method creates and returns a new attribute node.

var attributeNode = document.createAttribute(attributeName);

CreateComment

The createComment method creates and returns a new comment node.

var commentNode = document.createComment('this is my comment string');

CreateDocumentFragment

The createDocumentFragment method creates and returns a new DocumentFragment node.

var documentFragmentNode = document.createDocumentFragment();

CreateElement

The createElement method creates and returns a new HTML element.

// create object HTMLDivElement
var element = document.createElement('DIV');

CreateTextNode

The createTextNode method creates and returns a new TextNode.

var textNode = document.createTextNode('Hello World!');

GetElementById

The getElementById method returns an element object.

var element = document.getElementById('elementId');

GetElementsByTagName

The getElementsByTagName method returns a HTMLCollection that represents the elements in the document.

var paragraphsCollection = document.getElementsByTagName('p');

ImportNode

The importNode method copies a node from another document into the current document.

var importedNode = document.importNode(externalNode);

Open

The open method opens and clears a document for writing.

document.open();

Write

The write method is for writing to the document.

document.write('Hello World!');

Writeln

The writeln method is for writing to the document with a trailing newline character.

document.writeln('This is the first line');
document.writeln('This is the second line');

Resources

comments powered by Disqus