Last major update on 21 March 2008.
You can also view the previous version, which was created in September 2005 and still features IE Mac.
If you'd like to have some practical examples of what you can do with the W3C DOM, read my book ppk on JavaScript, especially chapter 8.
This compatibility table details support for the W3C DOM HTML Level 1 and 2 modules in all modern browsers.
There are four tables on this page. You must know the first two tables by heart, the other two are far less important.
First some properties of all HTML elements. All of them are read/write, and the average DOM script uses at least two or three of them.
You must know these properties by heart.
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
className
The class attribute.
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.className x.className = 'blue' Get or set the value of the |
|||||||||||
|
dir
The dir attribute.
Test page |
Yes | Buggy | Yes | Yes | Yes | Yes | |||||
x.dir x.dir = 'rtl' Get or set the text direction (ltr or rtl, left to right or right to left) of element For the moment dir serves as a glorified align. |
|||||||||||
|
id
The id attribute.
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.id x.id = 'otherID' Get or set the id of node |
|||||||||||
|
innerHTML
The HTML contained by a tag, as a string.Originally a Microsoft extension, innerHTML is so useful that all other browsers support it, too. Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.innerHTML x.innerHTML = "Let's <u>change</u> it!" Get or set the HTML contained by node Is innerHTML faster than the official Core methods like |
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|
innerText
The text contained by a tag.
Test page |
Yes | No | Yes | Yes | Yes | ||||||
x.innerText x.innerText = "Let's change it!" Get or set the text contained by node Cross browser: var text = x.innerText || x.textContent |
|||||||||||
|
outerHTML
The HTML of a tag, including the tag itself.
Test page |
Yes | No | Yes | Yes | No | ||||||
x.outerHTML x.outerHTML = "Let's <u>change</u> it!" Get or set the HTML of the entire node |
|||||||||||
|
outerText
The text of a tag, including the tag itself.
Test page |
Yes | No | Yes | Yes | No | ||||||
x.outerText x.outerText = "Let's change it!" Get or set the text contained by node |
|||||||||||
|
textContent
The text contained by a tag.
Test page |
No | Yes | Yes | Yes | Yes | ||||||
x.textContent x.textContent = "Let's change it!" Get or set the text contained by node Cross browser: var text = x.innerText || x.textContent |
|||||||||||
|
title
The title attribute.
Test page |
Yes | Yes | Minimal | Yes | Yes | Yes | |||||
x.title x.title = 'Changed' Get or set the title attribute of node
|
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
Some miscellaneous items, the first two of which are sometimes important.
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
body
The body tag
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
document.body Represents the BODY tag. |
|||||||||||
|
compatMode
Strict mode or Quirks mode
Test page Strict Test page Quirks |
No | Yes | Yes | No | Yes | Yes | Yes | ||||
document.compatMode Returns the compatibility mode of the document:
|
|||||||||||
|
create
Create an HTML document
Test page |
No | No | Yes | Yes | No | ||||||
document.implementation.createHTMLDocument('Title')
Create an HTML document consisting of |
|||||||||||
|
defaultView
The window the document is displayed in
Test page |
No | Yes | Yes | Yes | Yes | ||||||
document.defaultView Refers to the window. I have no idea why we need yet another reference to the window. |
|||||||||||
|
parentWindow
The window the document is displayed in
Test page |
Yes | No | No | Yes | No | ||||||
document.parentWindow Refers to the window. I have no idea why we need yet another reference to the window. |
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
Two new methods for select boxes.
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
add()
Add an option to a select box. The argument is an index number.
Test page |
Yes | Alter |
Yes | Yes | Yes | ||||||
x.add(y,x.options[x.options.length]) x.add(y,2) Adds an option to a select box, where The first line is the W3C approved way (but much too complicated): it requires you to refer to the option object after which the new option is inserted. The second line is the Microsoft way: give the index number of the option after which you want to insert the new option. I side with Microsoft here; W3C's implementation is far too complicated. Therefore support of the Microsoft model is required for a Yes here. Fortunately all browsers save IE and Firefox support both ways. |
|||||||||||
|
remove()
Remove an option from a select box
Test page |
Yes | Buggy | Yes | Yes | Yes | Yes | |||||
x.remove(1) Remove the second option from select
|
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
All methods, arrays and properties for child elements of tables. My W3C DOM vs. innerHTML tests show that these methods are the slowest way to build a table in Explorer on Windows. Use with care.
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
caption
The caption of a table
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.caption Access the caption of table |
|||||||||||
|
cellIndex
The index number of a cell in its row
Test page |
Yes | Incor |
Yes | Yes | Yes | Yes | |||||
x.cellIndex The index number of element
|
|||||||||||
|
cellPadding
The ancient attribute
Test page |
Yes | Yes | No | Yes | Yes | No | |||||
x.cellPadding = 10 Sets the cell padding of table
|
|||||||||||
|
cells[]
An array with all cells in a row
Test page |
Yes | No | Yes | Yes | Yes | Yes | |||||
x.rows[1].cells A nodeList with all cells of the second row of table |
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|
cellSpacing
The ancient attribute
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.cellSpacing = 10 Set the cell spacing of table |
|||||||||||
|
createCaption()
Create a caption for a table
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.createCaption() If table |
|||||||||||
|
createTFoot()
Create a tFoot element
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.createTFoot() If table |
|||||||||||
|
createTHead()
Create a tHead element
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.createTHead() If table |
|||||||||||
|
deleteCaption()
Delete the caption of a table
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.deleteCaption() Delete the caption of table |
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|
deleteCell()
Delete a table cell
Test page |
Yes | Untest |
Yes | Yes | Yes | Yes | |||||
x.rows[1].deleteCell(0) Delete the first cell of the second row of table |
|||||||||||
|
deleteRow()
Delete a table row
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.deleteRow(1) Delete the second row of table x.tBodies[1].deleteRow(1) Delete the second row of the second |
|||||||||||
|
deleteTFoot()
Delete the tFoot of a table
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.deleteTFoot() Delete the tFoot of table |
|||||||||||
|
deleteTHead()
Delete the tHead of a table
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.deleteTHead() Delete the tHead of table |
|||||||||||
|
frame
A border around an entire table
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.frame = 'lhs' Set the Possible values: void, above, below, hsides, vsides, lhs, rhs, box, border |
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|
insertCell()
Insert a table cell
Test page |
Yes | Untest |
Yes | Yes | Yes | Yes | |||||
x.rows[0].insertCell(1) Insert a |
|||||||||||
|
insertRow()
Insert a table row
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
| x.insertRow(1) Insert a |
|||||||||||
|
moveRow()
Move a row from one position to another. Microsoft proprietary.
Test page |
Yes | No | No | No | No | No | |||||
moveRow(0,3) Move row with index 0 to index 3. |
|||||||||||
|
rowIndex
The index number of a row in the table. Disregards table sections.
Test page |
Yes | Yes | Yes | Incor |
Yes | ||||||
x.rowIndex The index number of element Note that browsers should move any
|
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |
|
rows[]
An array of all rows in a table or table section
Test page |
Almost | No | Yes | Incor |
Yes | Incor |
Yes | ||||
x.rows A nodeList with all rows of table
|
|||||||||||
|
rules
I don't know what this property is supposed to do, unless it's meant
for removing the cellSpacing.
Test page Does not work |
Buggy | Buggy | Buggy | Buggy | No | ||||||
x.rules = 'rows' Sets the Possible values: none, groups, rows, cols, all
|
|||||||||||
|
sectionRowIndex
The index number of a row in the table section
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.sectionRowIndex The index number of element |
|||||||||||
|
tBodies[]
An array with all tBody elements
Test page |
Almost | No | Yes | Yes | Yes | Almost | |||||
x.tBodiesAn array with all TBodies of table x.
|
|||||||||||
|
tFoot
The tFoot of a table
Test page |
Almost | Yes | Yes | Yes | Almost | ||||||
| x.tFoot Access the tFoot of x, which must be a table.
|
|||||||||||
|
tHead
The tHead of a table
Test page |
Almost | Yes | Yes | Yes | Almost | ||||||
| x.tHead Access the tHead of x, which must be a table.
|
|||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b5 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.26 | Opera 9.5b | Konqueror 3.5.7 |