Steven Bontekoe

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromSteven Bontekoe
ToMe
SubjectWhy using childNodes for px?
Date7 August 2005 23:58
At first I want to thank you for the magnificent site you made.
I didn't knew that for position values you need to add px at the end, thanks for that.

at
http://www.howtocreate.co.uk/tutorials/javascript/dhtml
chapter: Using the reference to change the position

you are using the proprety document.childnodes in this sentence
"var noPx = document.childNodes ? 'px' : 0;"
What has this to do whether you need to add px behind the value off myReference.left?
I know some browsers need  px and others not, but what is the function of childnodes in this sentence?

thanks for responding
ps: I'm sorry for my bad english

greetz
Steven Bontekoe
FromMe
ToSteven Bontekoe
SubjectRe: Why using childNodes for px?
Date8 August 2005 10:16
Steven,

> "var noPx = document.childNodes ? 'px' : 0;"
> What has this to do whether you need to add px behind the value off
> myReference.left?
> I know some browsers need  px and others not, but what is the function of
> childnodes in this sentence?

The browsers that have problems with the use of "px" are all browsers that
do not fully support DOM. All DOM browsers expect to see "px" when you use a
strict doctype. All non-DOM browsers do not need it.

The use of childNodes is just a quick and simple way to see if the browser
supports DOM properly. If it does, then it is advanced enough to need to see
"px".

This actually has some relation to the way that DOM 2 CSS defined the style
object. Original pre-DOM implementations made things up their own way, and
basically allowed the missing 'px'. Some implementations insisted on not
using 'px'.

When the DOM came along, they said it was a direct mapping to the CSS, and
all styles could be changed to any value, and must be interpreted as if they
were CSS. CSS expects the units (although most implementations allow it in
quirks mode). Therefore, checking for the childNodes collection (one of the
fundamental parts of the DOM core [not DOM CSS but there is no easy way of
checking for DOM CSS support since the style object pre-dates DOM]) quickly
allows us to check if the browser is properly DOM compliant, and therefore
should expect the DOM 2 CSS response.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.