I am trying to read a custom (non-standard) CSS property, set in a stylesheet (not the inline style attribute) and get its value. Take this CSS for example:
#someElement { foo: 'bar'; }
I have managed to get its value with the currentStyle property in IE7:
var element = document.getElementById('someElement'); var val = element.currentStyle.foo;
But currentStyle is MS-specific. So I tried getComputedStyle() in Firefox 3 and Safari 3:
var val = getComputedStyle(element,null).foo;
…and it returns undefined. Does anyone know a cross-browser way of retreiving a custom CSS property value?
(As you might have noticed, this isn’t valid CSS. But it should work as long as the value follows the correct syntax. A better property name would be ‘-myNameSpace-foo’ or something.)
Firefox does not carry over tags, attributes or CSS styles it does not understand from the code to the DOM. That is by design. Javascript only has access to the DOM, not the code. So no, there is no way to access a property from javascript that the browser itself does not support.