JavaScript » Objects » Document

The Document object provides access to the elements in an HTML page from within your script. This includes the properties of every form, link and anchor (and, where applicable, any sub-elements), as well as global Document properties such as background and foreground colors.

Properties

alinkColor

Syntax: document.alinkColor = "colorinfo"

This property defines the color of an active link. The "colorinfo" argument is a string that can contain either the hexadecimal definition of the color or it's literal description.

anchors

Syntax: document.anchors["anchorID" ]

This property is an array containing references to all the named Anchor objects in the current document.

applets

Syntax: document.applets["appletID"]

This property is an array containing references to all the Applet objects in the current document.

bgColor

Syntax: document.bgColor = "colorinfo"

This property defines a document's background color. The "colorinfo" argument is a string that can contain either the hexadecimal definition of the color or it's literal description.

constructor

Syntax: Object.constructor

This specifies a function to create an object's property and is inherited by all objects from their prototype.

cookie

Syntax: document.cookie[ = "expression(s)"]

This property is a string that returns a report detailing all visible and un-expired cookies that are associated with the specified document.

domain

Syntax: document.domain = "domaininfo"

This property sets or returns the domain name of the server from which the document originated.

embeds

Syntax: document.embeds["embed_objID" ]

This property is an array containing references to all the embedded objects in the current document.

fgColor

Syntax: document.fgColor = "colorinfo"

This property defines a document's foreground (text) color. The "colorinfo" argument is a string that can contain either the hexadecimal definition of the color or it's literal description.

formName

Syntax: document."formname"

Every form in a document has a separate document object property, the name of which is taken from the value asigned to the form with the <FORM NAME = "formID"> tag. Any form in the document can then be referred to with the syntax below.

forms

Syntax: document.forms["formID" ]

This property is an array containing references to all the Form objects in the current document.

images

Syntax: document.images["imageID"]

This property is an array containing references to all the Image objects in the current document.

lastModified

Syntax: document.lastModified

This property returns the date that the document was last modified.

layers

Syntax: document.layers["layerID"]

This property is an array containing references to all the Layer objects in the current document.

linkColor

Syntax: document.linkColor = "colorinfo"

This property defines the color of any hyperlinks in the document. The "colorinfo" argument is a string that can contain either the hexadecimal definition of the color or it's literal description.

links

Syntax: document.links["linkID"]

This property is an array containing references to all the Area and Link objects in the current document.

plugins

Syntax: document.plugins["pluginID"]

This property is an array containing references to all the Plugin objects in the current document.

prototype

Syntax: Object.prototype.name = value

This allows the addition of properties and methods to any object.

referrer

Syntax: document.referrer

If a destination document is reached by a user clicking on a Link object in another document (the referrer), this property returns the referring document's URL.

title

Syntax: document.title

This property returns the document's name as defined between the <TITLE></TITLE> tags.

URL

Syntax: document.URL

This property is used to retrieve the document's full URL.

vlinkColor

Syntax: document.vlinkColor = "colorinfo"

This property defines the color of any visited links in the document. The "colorinfo" argument is a string that can contain either the hexadecimal definition of the color or it's literal description.

Methods

captureEvents

Syntax: document.captureEvents(eventType)

This method instructs the document to capture and handle all events of a particular type. See the event object for a list of event types.

close

Syntax: document.close( )

This method closes an output stream previously opened with the document.open method and forces data collected from any instances of the document.write or document.writeln methods to be displayed.

eval

Syntax: Object.eval(string)

The eval method is deprecated as a method of Object, but is still used as a high level function. It evaluates a string of JavaScript in the context of an object.

getElementById

Syntax: document.getElementById(id)

This element receives a string containing the id of a specific element and returns a reference to it.

getSelection

Syntax: document.getSelection( )

This method can be used to return the contents of selected text in the current document.

handleEvent

Syntax: document.handleEvent(event)

This method calls the handler for the specified event.

open

Syntax: document.open([mimeType[, replace]])

This method is used to open a stream to collect the output from any write or writeln methods.

releaseEvents

Syntax: document.releaseEvents(eventType)

This method is used to set the document to release any events of the type eventType and passes them along to objects further down the event heirarchy.

routeEvent

Syntax: document.routeEvent(event)

This method is used to send the event specified along the normal event hierarchy.

toSource

Syntax: Object.toSource()

The toSource method returns a literal representing the source code of an object. This can then be used to create a new object.

toString

Syntax: Object.toString()

The toString method returns a string representing a specified object.

unwatch

Syntax: Object.unwatch(property)

This method removes a watchpoint set for an object and property name with the watch method.

valueOf

Syntax: Object.valueOf()

This method returns a primitive value for a specified object.

watch

Syntax: Object.watch(property, handlerfunction)

This method adds a watchpoint to a property of the object.

write

Syntax: document.write("expression1", [expression2, [...]])

This method is used to write HTML expressions to the specified document.

writeln

Syntax: document.writeln("expression(s)")

This method is identical to the write method detailed above, with the addition of writing a new line character after any specified expressions.

See Also: