Thursday, September 16, 2004

HTML DOM Document Object

Document Object

The Document object is used to access all elements in a page.

The Document object's collections, properties, methods, and events are described below:

N: Netscape (including Mozilla when N6 or higher), IE: Internet Explorer, W3C: World Wide Web Consortium (Internet Standard), D: Deprecated

Collections

Collection Description N IE W3C
anchors[] Returns a reference to all Anchor objects in the document 2 3 Yes
applets[] Returns a reference to all Applet objects in the document 3 4 Yes
attributes[] 6 - No
childNodes[] 6 5 No
embeds[] Returns a reference to all embedded objects in the document 3 4 No
forms[] Returns a reference to all Form objects in the document 2 3 Yes
images[] Returns a reference to all Image objects in the document 3 4 Yes
links[] Returns a reference to all Link objects in the document 2 3 Yes
plugins[] 6 - No
sylesheets[] 6 5 No

Properties

Syntax: document.property_name

Property Description N IE W3C
alinkColor Sets or returns the color of the active links in the document 2 3 D
bgColor Sets or returns the background-color of the document 2 3 D
body Specifies the beginning and end of the document body 6 5 Yes
cookie Sets or returns all cookies associated with the document 2 3 Yes
documentElement Returns a reference to the root node of the document 6 5 No
domain Returns the document server's domain name 3 4 Yes
fgColor Sets or returns the text-color of the document 2 3 D
lastModified Returns the date and time the document was last modified 2 3 No
linkColor Sets or returns the color of the links in the document 2 3 D
referrer Returns the URL of the document that loaded the current document 2 3 Yes
title Returns the title of the document (text inside the HTML title element) 2 3 Yes
URL Returns the URL of the current document 3 4 Yes
vlinkColor Sets or returns the color of the visited links in the document 2 3 D

Methods

Syntax: document.method_name()

Method Description N IE W3C
clear() Clears all elements in the document 2 - No
close() Closes the output stream and displays the sent data 2 3 Yes
createAttribute("name") Creates an attribute with a specified name 6 6 No
createElement("tag") Creates an element 6 5 No
createTextNode("txt") Creates a text string 6 5 No
focus() Gives the document focus 6 5 No
getElementById("id") Returns a reference to the first object with the specified ID 6 5 No
getElementsByName("name") Returns a collection of objects with the specified NAME 6 5 Yes
getElementsByTagName("tag") Returns a collection of objects with the specified TAGNAME 6 5 No
open("mimetype"[,replace]) Opens a document for writing. If a document exists in the target it will be cleared. If this method has no arguments, a new window with about:blank is displayed 2 3 Yes
write("str") Writes a text string to a document opened by open() 2 3 Yes
writeln("str") Writes a text string followed by a new line character to a document opened by open() 2 3 Yes

Events

Syntax: document.event_name="someJavaScriptCode"

Event Description NN IE W3C
onClick Executes some code when a Click event occurs 6 5
onDblClick Executes some code when a Doubleclick event occurs 6 5
onFocus Executes some code when a Focus event occurs 6 5
onKeyDown Executes some code when a Keydown event occurs 6 5
onKeyPress Executes some code when a Keypress event occurs 6 5
onKeyUp Executes some code when a Keyup event occurs 6 5
onMouseDown Executes some code when a Mousedown event occurs 6 5
onMouseMove Executes some code when a Mousemove event occurs 6 5
onMouseOut Executes some code when a Mouseout event occurs 6 5
onMouseOver Executes some code when a Mouseover event occurs 6 5
onMouseUp Executes some code when a Mouseup event occurs 6 5
onResize Executes some code when a Resize event occurs 6 5



No comments: