The document object is an object that is created by the browser for each HTML page (document) that is viewed.
Document Object Properties
activeElement - Gets the object that has the focus when the parent document has focus. (Support: IE4+)
anchors - Returns an array of all of the anchors in the document.
applets - Returns an ordered array of the applets within a document.
async - Used with document.load to indicate an asynchronous request. (Support: FF1.5+)
body - Returns the BODY node of the current document.
characterSet - Returns the character set being used by the document. (Support: FF1+, NN6+)
charset - Sets or retrieves the character set used to encode the object. (Support: IE4+)
childNodes - An array of all of the child nodes of the document
contentType - Returns the Content-Type from the MIME Header of the current document. (Support: FF1+, NN7+)
cookie - Returns a semicolon-separated list of the cookies for that document or sets a single cookie.
defaultCharset - Gets the default character set from the current regional language settings. (Support: IE4+)
defaultView - Returns a reference to the window object. (Support: FF1+, NN6+)
designMode - Gets and sets WYSYWIG editing capability. Used in an iFrame.
doctype - Returns the doctype declaration associated with the document
documentElement - Returns the Element that is a direct child of a document. For HTML documents, this is normally the HTML element.
domain - Returns the domain of the current document.
embeds - Returns an array of the embedded OBJECT's within the current document.
expando - Sets or retrieves a value indicating whether arbitrary variables can be created within the object. (Support: IE4+)
forms - Returns an array of the FORM elements within the current document.
height - Gets and sets the height of the current document in pixels. (Support: FF1+, NN4+)
images - An array of all the image (img) tags in the document
implementation - The DOM implementation associated with the current document.
lastModified - Returns the date of the last modification of the document
links - An array of all the link (<a>) tags in the document
location - Gets and sets the location, or current URL, of the window object.
plugins - An array of all the plugins used in the document
readyState - A string value that represents the current state of the document
referrer - The page that linked to this page.
styleSheets - An array of all the style sheets used in the document
title - The text used inside the title tags of the document
URL - The URL of the current document
width - Returns the width of the current document. (Support: FF1+, NN4+)
xmlEncoding - Returns the encoding as determined by the XML declaration. (Support: FF1.5+)
- Exemples with some of these properties:
1) Display and change the text from TITLE meta-tag
document.write(document.title); // Document Object - DOM
document.title = 'New title'; // "New title" will appear in the tittle bar
2) In the following example, the JS script gets and writes the domain and the complete URL of the page.
var domain_site = document.domain;
var url = document.URL;
document.write(domain_site+ '<br />'); // coursesweb.net
3) In the next example three link tags are defined and a JS script writes the address from the second link.
- Exemples with some of these methods:
1) The following script displays an alert with the text added in a tag with id="an_id"
<div id="an_id">JS lessons and tutorials</div>
var str = document.getElementById('an_id');
alert(str.innerHTML); // JS lessons and tutorials
- the expresion this.id gets the value of the ID attribute added in own element.