It was mentioned on an earlier page that the DOM has progressed to level 4 at the time of writing. Here we consider the original level 0 version. Nowadays there are easier ways of doing things but this structure is still present.
Elements on an HTML page are represented by objects or arrays which can be accessed by the script. They are properties of an object called document
, of class Document
.
For example, if the page contains a hyperlink, written in HTML as
<a name="abc" href="xyz">XYZ</a>
then script can access this as document.links ["abc"]
or as document.links [n]
if this is the nth link in the page (counting from 0).
all []
- all objects on the pageanchors []
- <a> elements that are link targetsbgColor
- the background colour of the pagecookie
- see next pagefgColor
- the foreground colour of the pageforms []
- there may be several input forms on a pageimages []
- the <img>
elements on the pagelastModified
- date (of type Date
) when page was last modifiedlinkColor
- colour used for linkslinks []
- all the links on the pagetitle
- the title of the pageURL
- the address of the pageMany of those are awkward to use because you would need to know the numbered sequence of objects on the page, so they are rarely used now. It is much simpler to use id
attributes on elements you need to access, as we have been doing from the beginning of this course. The id
technique was not available in the original DOM, used by early browsers.
window
represents the window in which the program is running.
location
holds the URL from which the current page was loaded. Properties of this object include
navigator
represents the browser and device in which the program is running.
screen
has details of the physical screen.
history
enables some navigation of the user's browsing history, such as going back but this is quite limited for security reasons.