JavaScript Document Object

The JavaScript Document object is the container for all HTML HEAD and BODY objects associated within the HTML tags of an HTML document.

Document Object Properties

  • alinkColor - The color of active links.
  • bgColor - Sets the background color of the web page. It is set in the <body> tag. The following code sets the background color to white.

    document.bgColor = "#FFFFFF"

  • cookie - Used to identify the value of a cookie.
  • defaultCharset
  • domain - The domain name of the document server.
  • embeds - An array containing all the plugins in a document.
  • fgColor - The text color attribute set in the <body> tag.
  • FileCreatedDate - Use this value to show when the loaded HTML file was created
  • fileModifiedDate - Use this value to show the last change date of the loaded HTML file
  • fileSize
  • fileUpdatedDate
  • lastModified - The date the file was modified last.
  • layers - An array containing all the layers in a document.
  • linkColor - The color of HTML links in the document. It is specified in the <body> tag.
  • location
  • mimeType
  • nameProp
  • protocol
  • readyState
  • referrer - The Universal Resource Locator (URL) of the document that we got the link to the present document from.
  • security
  • title - The name of the current document as described between the header TITLE tags.
  • URL - The location of the current document.
  • vlinkColor - The color of visited links as specified in the <body> tag/

Document Object Methods

  • clear() - This is depreciated.
  • close() - Closes an output stream that was used to create a document object.
  • contextual() - It can be used to specify stype of specific tags. The following example specified that text in blockquotes is to be blue:

    document.contextual(document.tags.blockquote).color = "blue";

    Multiple styles may be specified in the contextual method to set the value of text in a H3 tag that is underlined to the color blue, for example.

    document.contextual(document.tags.H3, document.tags.U).color = "blue";

  • elementFromPoint(x, y) - Returns the object at point x, y in the HTML document.
  • getSelection() - Get the selected text (if any is selected).
  • open([mimeType]) - Opens a new document object with the optional MIME type.
  • write(expr1[,expr2...exprN]) - Add data to a document. Writes the values passed to the write function to the document.

    document.write("<H3>") document.writeln("This is a Header") document.write("</H3>")

  • writeln(expr1[,expr2...exprN]) - Adds the passed values to the document appended with a new line character.


  • onafterupdate
  • onbeforeupdate
  • onClick
  • ondblclick
  • ondragstart
  • onerrorupdate
  • onhelp
  • onkeydown
  • onkeypress
  • onkeyup
  • onmousedown
  • onmousemove
  • onMouseOut
  • onMouseOver
  • onmouseup
  • onreadystatechange
  • onrowenter
  • onrowexit
  • onselectstart

Document Object Objects

  • activeElement
  • all - All HTML elements in the document.
  • anchors - An array of all the anchors in the document.
  • applet - A JAVA applet to be used in the document.
  • area - An object specifying an image map area contained in the document.
  • body
  • embeds
  • form - An object that specifies a form in the document.
  • forms - An array of all the forms in the document.
  • frames - An array that consists of all the frame objects in the document.
  • images - An array of the images in the document.
  • image - An image in a document. Properties of the image:
    • border - The width of the border around the image in pixels.
    • complete - A boolean value which identifies whether an image is completely loaded yet.
    • height - The read only height of the image in pixels.
    • hspace - The read only amount of horizontal space to the left and right sides of the image.
    • lowsrc - The read or write string giving the URL of an alternate image for low resolution screen display.
    • name - The assigned name of the image.
    • prototype - Used for adding user-specified properties to the image.
    • src - The URL of the image to be displayed. It is a read/write string.
    • vspace - The read only vertical space above and below the image.
    • width - The read only width of the image in pixels.
  • links - An array of all the links in the document.
  • link - A link in the document. Properties:
    • hash - The URL anchor part including the leading hash mark if one exists.
    • host - The URL hostname and port.
    • hostname - The URL hostname section.
    • href - The URL.
    • pathname - The URL pathname section.
    • port - The URL port section.
    • protocol - The URL protocol section including the colon after the protocol name.
    • search - The URL query string section. This is the section after and including the question mark.
    • target - The URL link’s target name.
  • parentWindow - The parent window of the document.
  • plugins - An array of plugins in the document.