6.2.1. The document Object

JavaScript provides the document object for manipulating the document that is currently visible in the browser window.

The document object can be created using the following HTML tag:

[BACKGROUND = “backgroundImage]
[BGCOLOR = “backgroundColor”]
[FGCOLOR = “foregroundcolor”]
[LINk = “linkColor”]
[ALINK= “activeLinkColor”]
[VLINK = “visited LinkColor”]

The document object has many useful properties and methods, which are listed in Table 6.1.  It includes methods such a document.write and document.writein, both which have been used in the prior JavaScript examples.  The properties of the document object can be set using the following syntax.


document.property = value;


Document.bgColor =”green “
Document.cookie = “mycookie”

The methods of the document object can be called using the following syntax:

Syntax: document.method (argument)

Eg:    document.write (“This is a document output”);


The following example uses some of the document objects’ properties and methods.

Example6.1 – Using document object properties and methods:

<title> the complete HTML document is shown below </title>
<script> var a,f;
Function color(f,a)
document.bgcolor = a;
<body> <form name = “myform”>
<input type = button value = “red”onClick = color(this.form,”red”)>
<input              type = “button” value = “green” onClick = color(this.form.”green”)>
<input type = “button” value = “cyan”onClick = color(this.form,”cyan”)>
<strong>Note:</strong> JavaScript is case sensitive.  Not using the proper uppercase and lowercase letters is a syntax error.  A syntax error occurs when the script interpreter cannot recognize a statement.  The interpreter normally issues an error message to help the programmer locate and fix the error.
Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

Your email address will not be published. Required fields are marked *

− 5 = two

Popup Dialog Box Powered By : XYZScripts.com
  • RSS
  • Facebook
  • Google+
  • Twitter