...

View Full Version : How to access min and max CSS properties from JS



krycek
08-26-2006, 03:46 PM
It would appear that it is not possible to retrieve CSS properties such as min-width if they have been set from a class. However, I don't want to have to style everything directly with the style attribute whenever I need these properties. Is there a reliable method of getting these properties as applied to element from a CSS class?

jkd
08-26-2006, 05:30 PM
someElement.style refers to CSS properties that have been set in its style attribute. So it's not just max-width, but any property.

In standards-compliant browsers such as Safari, Opera, and Firefox:


document.defaultView.getComputedStyle(someElement, "").getPropertyValue("max-width")


Will obtain the computed value for max-width.

Similarly in IE:


someElement.currentStyle.maxWidth

(even though IE<7 doesn't support the max-width property)

krycek
08-26-2006, 05:35 PM
In standards-compliant browsers such as Safari, Opera, and Firefox:


document.defaultView.getComputedStyle(someElement, "").getPropertyValue("max-width")


Cool, that's what I was after. I knew about currentStyle but I didn't know about getComputedStyle.

Thanks jkd! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum