Last major update on 21 March 2008.
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.
These compatibility tables detail support for the W3C CSSOM View specification in all modern browsers.
These properties hold the dimensions of the entire browser window.
| Event | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
innerWidth and innerHeight
The dimensions of the viewport (interior of the browser window)
Test page |
No | Yes | Yes | Yes | Yes | ||||||
window.innerWidth window.innerHeight |
|||||||||||
|
outerWidth and outerHeight
The dimensions of the entire browser window (including taskbars and such)
Test page |
No | Yes | Yes | Yes | Yes | ||||||
window.outerWidth window.outerHeight |
|||||||||||
|
pageXOffset and pageYOffset
The amount of pixels the entire pages has been scrolled
Test page |
No | Yes | Yes | Yes | Yes | ||||||
window.pageXOffset window.pageYOffset |
|||||||||||
|
screenX and screenY
The position of the browser window on the screen
Test page |
No | Yes | Yes | Incor |
Yes | ||||||
window.screenX window.screenY
|
|||||||||||
| Event | 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 |
These properties hold information about the screen.
| Event | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
availWidth and availHeight
The available width and height on the screen (excluding OS taskbars and such)
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
screen.availWidth screen.availHeight |
|||||||||||
|
colorDepth
The color depth (in bits) of the screen
Test page |
Yes | Yes | Incor |
Yes | Yes | Yes | |||||
screen.colorDepth FF3b4 suddenly gives 24 for my 32-depth screen. |
|||||||||||
|
pixelDepth
Same as colorDepth
Test page |
No | Yes | Incor |
Yes | Yes | Yes | |||||
screen.pixelDepth FF3b4 suddenly gives 24 for my 32-depth screen. And no, I don't understand why we need a property that contains the same information
as |
|||||||||||
|
width and height
The width and height of the screen
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
screen.width screen.height |
|||||||||||
| Event | 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 |
| Event | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
elementFromPoint()
Returns the element located at the given coordinates
Test page |
Yes | No | Yes | Alter |
Incor |
No | |||||
document.elementFromPoint(100,100) Which coordinates does
This method is a godsend for drag and drop scripts. When the user drops the dragged element, figure out what element is located at the drop point and go on from there. No more complicated calculations necessary. However, you need to temporarily hide the dragged object. By definition it's the topmost element on the requested coordinates, and we need to know what's underneath it. The basic trick is:
releaseElement: function(e) { // called onmouseup
var evt = e || window.event;
draggedObject.style.display = 'none';
var receiver = document.elementFromPoint(evt.clientX,evt.clientY);
draggedObject.style.display = '';
Now |
|||||||||||
A few methods that give information about the element.
| Event | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
getBoundingClientRect()
Gets the encompassing rectangle
Test page |
Yes | No | Almost | No | No | Yes | No | ||||
x.getBoundingClientRect() Returns an object that contains the IE handles this correctly, provided you accept its incorrect calculation of the individual rectangles.
|
|||||||||||
|
getClientRects()
Gets the several rectangles of an element
Test page |
Incor |
Almost | No | Almost | No | No | Yes | No | |||
x.getClientRects() Returns a list with Rectangle objects that contain the The trick here is, that an inline element such as an
|
|||||||||||
|
scrollIntoView()
Makes an element scroll into view (Not part of the specification) Test page |
Yes | Yes | Yes | Yes | No | ||||||
x.scrollIntoView() Element Essentially element | |||||||||||
| Event | 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 |
These properties give information about the dimensions of an Element node (HTML tag).
| Event | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
|
clientLeft and clientTop
The position of the upper left corner of the content field relative to the upper left
corner of the entire element (including borders)
Test page |
Yes | No | Yes | Yes | Yes | No | |||||
x.clientLeft x.clientTop |
|||||||||||
|
clientWidth and clientHeight
The width and height of the content field, excluding border and scrollbar, but including padding
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.clientWidth x.clientHeight |
|||||||||||
|
offsetLeft and offsetTop
The left and top position of the element relative to its offsetParent.
Test page |
Incor |
Alter |
Yes | Yes | Yes | Yes | |||||
x.offsetLeft x.offsetTop
|
|||||||||||
| Event | 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 |
|
offsetParent
The ancestor element relative to which the offsetLeft/Top are calculated.
Test page |
Yes | Buggy | Yes | Yes | Yes | Yes | |||||
x.offsetParent When calculating the
The In IE and Opera
elements with
|
|||||||||||
|
offsetWidth and offsetHeight
The width and height of the entire element, including borders
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
x.offsetWidth x.offsetHeight |
|||||||||||
|
scrollLeft and scrollTop
The amount of pixels the element has scrolled. Read/write.
Test page |
Yes | No | Yes | Yes | Yes | Yes | |||||
x.scrollLeft x.scrollTop x.scrollTop = 20 |
|||||||||||
|
scrollWidth and scrollHeight
The width and height of the entire content field, including those parts that are
currently hidden. (Another way of saying the same: it's the width and height the element
would have if it had width: auto; height: auto;.)If there's no hidden content it should be equal to clientX/Y. Test page |
Incor |
Buggy | Yes | Yes | Incor |
Yes | |||||
x.scrollWidth x.scrollHeight When you scroll the element all the way down, If the element has no scrollbars
|
|||||||||||
| Event | 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 |
Calculating the mouse position (relative to what?) used to be a JavaScript disaster area. Fortunately the browsers are getting their act together.
| Event | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
clientX,clientY
window
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
event.clientX event.clientY Returns the mouse coordinates relative to the window. |
|||||||||||
offsetX, offsetY
target
Test page |
Buggy | pageX/Y | No | Incor |
Incor |
Incor |
|||||
event.offsetX event.offsetY Returns the mouse coordinates relative to the event's target. But exactly which point in the box serves as a reference point? The spec says the top/left of the padding box, but Opera uses the top/left of the content box, and Safari and Konqueror the top/left of the border box. A nice conundrum. For the moment I'm sticking to the spec.
|
|||||||||||
| Event | 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 |
pageX, pageY
document
Test page |
No | Yes | Yes | Yes | Yes | ||||||
event.pageX event.pageY Returns the mouse coordinates relative to the document. Most of the time this is the information you want.
In order to get it in IE, too, add the scrolling offset of the document to |
|||||||||||
screenX, screenY
screen
Test page |
Yes | Yes | Yes | Yes | Yes | ||||||
event.screenX event.screenY Returns the mouse coordinates relative to the screen. |
|||||||||||
x, y
Equal to clientX/Y
Test page |
Yes | No | Yes | Yes | Yes | ||||||
|
Nobody can explain why we need |
|||||||||||
| Event | 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 |