HTML Dom Document Object
Document Object
Each HTML document loaded into the browser will become a Document Object.
The document object allows us to access all elements in the HTML page from the script.
Tip: The document object is part of the window object and can be accessed through the document DOC ument attribute.
IE: Internet Explorer, F: Firefox,
O: Opera, W3C: W3C standard.
Document Object set
| Set |
Description |
IE |
F |
O |
W3C |
| All [] |
Provides access to all HTML elements in the document. |
4 |
1 |
9 |
No |
| Anchors [] |
Returns a reference to all anchor objects in the document. |
4 |
1 |
9 |
Yes |
| Applets |
Returns a reference to all the applet objects in the document. |
- |
- |
- |
- |
| Forms [] |
Returns reference to all form objects in the document. |
4 |
1 |
9 |
Yes |
| Images [] |
Returns a reference to all image objects in the document. |
4 |
1 |
9 |
Yes |
| Links [] |
Returns reference to all Area and Link objects in the document. |
4 |
1 |
9 |
Yes |
Document Object Attributes
| Attribute |
Description |
IE |
F |
O |
W3C |
| Body |
Provides direct access to the <body> element. For documents that define a framework set, this attribute references the <frameset> of the outermost layer. |
|
|
|
|
| Cookie |
Sets or returns all cookies related to the current document. |
4 |
1 |
9 |
Yes |
| Domain |
Returns the Domain Name of the current document. |
4 |
1 |
9 |
Yes |
| Lastmodified |
Returns the date and time when the document was last modified. |
4 |
1 |
No |
No |
| Referrer |
Returns the URL of the document that loads the current document. |
4 |
1 |
9 |
Yes |
| Title |
Returns the title of the current document. |
4 |
1 |
9 |
Yes |
| URL |
Returns the URL of the current document. |
4 |
1 |
9 |
Yes |
Document Object Method
| Method |
Description |
IE |
F |
O |
W3C |
| Close () |
Close the output stream opened using document. open () and display the selected data. |
4 |
1 |
9 |
Yes |
| Getelementbyid () |
Returns a reference to the first object with the specified ID. |
5 |
1 |
9 |
Yes |
| Getelementsbyname () |
Returns a set of objects with the specified name. |
5 |
1 |
9 |
Yes |
| Getelementsbytagname () |
Returns an object set with the specified tag name. |
5 |
1 |
9 |
Yes |
| Open () |
Open a stream to collect output from any document. Write () or document. writeln () method. |
4 |
1 |
9 |
Yes |
| Write () |
Write HTML expressions or JavaScript code to the document. |
4 |
1 |
9 |
Yes |
| Writeln () |
It is equivalent to the write () method. The difference is that a line break is written after each expression. |
4 |
1 |
9 |
Yes |
Document Object Description
The htmldocument interface extends the DOM Document Interface and defines HTML-specific attributes and methods.
Many Attributes and methods are htmlcollection objects (in fact, read-only arrays that can be indexed with arrays or names), which store references to the anchor, forms, links, and other Scriptable elements.
These set attributes are derived from level 0 Dom. They have been
Document. getelementsbytagname () is replaced, but it is often used because it is convenient.
The write () method is worth noting that when a document is loaded and parsed, it allows a script to insert dynamically generated content into the document.
Note that in level 1 Dom, htmldocument defines
Getelementbyid () is a very useful method. In Level 2 Dom, this method has been transferred to the document interface, which is now inherited by htmldocument rather than defined by it.