The document object represents the current document or web page loaded in the browser. It has properties that define things like colors and elements of the page, and methods that can manipulate the document, like write. Some key properties are bgColor and fgColor for background and text colors, URL for the page address, and anchors for all named anchors on the page. Methods include write to output text to the document. The document object provides an interface to access and change attributes of the currently loaded page.
2. The Document Object
• Defining the Document Object
• Using the Properties of the Document Object
• Using the Methods of the Document Object
3. Defining the Document Object
• The document object is an object that is created by the
browser of each new HTML page(document) that is
viewed.
• By doing this, JavaScript gives you access to a number of
properties and methods that can affect the document in
various ways.
• You have been using the write() method of the document
object.
4. Using the Properties of the
Document Object
• alinkColor
• Anchors
• bgColor
• dir
• fgColor
• formName
• linkColor
6. Using the Properties of the
Document Object
• alinkColor
The alinkColor property holds the value of the active link
color(the color of a link when it is clicked) for the HTML
document.
Returns the hexadecimal value of the active link color of the
document.
7. Using the Properties of the
Document Object
• Anchors
The anchors property is actually an array that is set by the
browser for all the named anchors in a document (such as
<A NAME=“top”>).
An array of all the named anchors in the document.
8. Using the Properties of the
Document Object
• bgColor
The bgColor property holds the value of the background
color of a Web page.
Returns the hexadecimal value of the background color of
the document.
Eg: document.bgColor = “lightblue”;
9. Using the Properties of the
Document Object
• dir
The dir property returns a string value that represents the readin
direction of the document.
This value can be either ltr(left to right) or rtl(right to left).
Eg: document.dir = “rtl/ltr”;
10. Using the Properties of the
Document Object
• fgColor
The fgColor property is the equivalent of the regular text color on a
Web page.
The “fg” in this property stands for foreground.
Returns the hexadecimal value of the default text color of the
document.
Eg: document.fbColor
11. Using the Properties of the
Document Object
• formName
The formName property isn’t actually a property itself.
Any time you name a form, you create a formName property, but
the property is actually the name of the form and not formName.
12. Using the Properties of the
Document Object
• linkColor
The linkColor property holds the value of the link color of the
document.
Returns the hexadecimal value of the default link color for the
document
Eg: document.linkColor = “#0000FF”;
13. Using the Properties of the
Document Object
• URL
The URL property holds the value of the full URL of the current
document.
This information can be useful if you print it at the bottom of
your HTML page, because it will show the page URL for anyone
who prints out your page.
Returns the URL of the current document
14. Using the Properties of the
Document Object
• vlinkColor
The vlinkColor property holds the RGB code for the visited link
color on a Web page.
Returns the hexadecimal value of the visited link color for the
document.
Eg: document.vlinkColor = “#0000FF”;