The Document Object Model in DHTML


The Document Object Model (DOM) is the road map through which one can locate any element in an HTML document and use a script, such as JavaScript, to change that element's properties. Refer to two JavaScript Object reference pages connected by the links below for details of the Document Object Model.

Note that the Netscape and Internet Explorer Document Object Models do have differences. Thus some object exist in either browser which do not exist in the other.

Detecting Browser Type and Version

Detect different browser versions as shown below when deciding what to use in each browser. For instance, different versions of JavaScript (1.2 or 1.3 for browser version 4 and 5 respectively) and different DHTML properties in different browsers and even differences in HTML tags.

if (isNS4 || isIE4 || isNew)
{
	{ DHTML Code }
}
else
{
	{ non-DHTML code }
}

Cross-Browser Document Object Model

The different browsers and their respective versions are detected as shown in the piece of code shown above. When a result is found different sections of code are executed based on what functions correctly within each respective browser.

Detecting Features

In general this is the necessity for detecting which parts of the Document Object Model function in specific browsers. We can check for the existence of objects within a browser as shown below and thus take the appropriate steps.

if (document)
{
	if (document.images)
	{
		{ Do something with the document.images array }
	}
}