It is vital for me to know what the actual CSS rule is. Is there
something besides getComputedStyle?
My end goal is to find the largest static-width element on the page.
If I cannot read stylesheet values - only rendered/computed values -
then how can I achieve this?
The code I'm currently using:
function getStyle(elem, name) {
if (elem.style[name]) {
return elem.style[name];
} else if (elem.currentStyle) {
return elem.currentStyle[name];
}
else if (document.defaultView &&
document.defaultView.getComputedStyle) {
name = name.replace(/([A-Z])/g, "-$1");
name = name.toLowerCase();
s = document.defaultView.getComputedStyle(elem, "");
return s && s.getPropertyValue(name);
} else {
return null;
}
}
> I am trying to get the width of an element according to it's CSS rules
> (you can see the code I am using below). The problem is that
> "getComputedStyle" returns a pixel value instead of "auto" for an
> element with no CSS width value set. In Opera,
> "elem.currentStyle['width']" returns "auto", but in firefox, it must
> use "getComputedStyle" which returns something like "1149px".
>
> It is vital for me to know what the actual CSS rule is. Is there
> something besides getComputedStyle?
>
https://developer.mozilla.org/en/CSS/used_value
says
"...a script can read only the final used values with
window.getComputedStyle."
--
(Remove any numerics from my email address.)
Fair enough. So then, to be clear, there is no way to determine if an
element has a static or floating width?
I am not an expert. From reading that and other pages I think that
what you want is what MDN calls 'specified value'. The pages do not
say you cannot get at that, but they do not mention a way to do it. In
my experience MDN would refer to such a method if there were one.
But to be sure, I would ask on the NG sailfish posted, or ask on Stack
Overflow.