On Sat, Feb 12, 2011 at 8:18 PM, Peter van der Zee <[email protected]> wrote: > On Sat, Feb 12, 2011 at 3:46 PM, clothears <[email protected]> wrote: >> >> > > It appears that if I set some value using CSS, then I am unable to >> > > read that value with JavaScript. I have, instead, to not bother >> > > setting it with CSS, but instead to initialise it (to the same value) >> > > with JavaScript, and then I find I can read it back correctly. Is this >> > > expected behaviour? >> > >> > Yes. I'm assuming you're trying to read these values through the >> > el.style >> > object. This is safe for writing, but not for reading. To read (any >> > currently applied style for a specific element), there are two ways to >> > go: >> >> Umm no. If I take as a specific example the left padding of a <div>, >> ... >> pad = parseInt (document.getElementById("xyz").style.paddingLeft); > > Yeah. This is "trying to read these values through the el.style object". It > doesn't work that way. It works in some ways, but it's unreliable. The > computed styles is by far more reliable. > >> >> But why can I not read it as above? > > Because, simply put, that's not how browsers implement it. You need to get > the computed styles like I've shown you on IE and non-IE. > I wonder whether IE9 does getComputedStyle yet...
Yes, seems IE9 will have "getComputedStyle()" and probably the implementation will be on par of other browsers. I say probably will because in some of the beta preview IE9 still needed camel cased property names in "getPropertyValue()" method. Haven't tried this in the very latest RC but I was told it was solved. -- Diego > - peter > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
