I’ve found the need to extract the set style of an element in a browser (done by the user). I have to be able to work with the retrieved styles on my server (server sided javascript and jQuery). Now, the problem is that many browsers appear to use their own naming conventions or like to separate shorthands to individual elements, while others do not.
One solution for me would be to get the literal style string of an element (styles from stylesheets do not have to be accounted for). In Firefox/Chrome this would work:
node.getAttribute('style')
Unfortunately, this is not possible in Internet Explorer 5/6/7. I figured this would be a solution:
function getStyleStr(node) {
return typeof(node.getAttribute('style')) !== 'string' ? node.style.cssText : node.getAttribute('style');
}
Unfortunately, node.style.cssText does not return the literal string as described here: http://javascript.gakaa.com/style-csstext.aspx
Is there a better way to detect the set style of an element in a cross browser way with the same names?
http://upshots.org/?p=112
You’ll need to access the computed style and or current style of the dom element. That should give you everything you need and it will take into consideration all forms of styles (inline, declared css & inherited properties)