Take a look at this example to see the issue in action.
I'm attempting to access the cssText
property of a <div>
using window.getComputedStyle(element)
(which provides a CSSStyleDeclaration object). While this works smoothly in Chrome, it's not functioning as expected in Firefox and IE10 and IE11. In those browsers, the cssText
property is present on the returned object but contains an empty string.
I haven't tested this in older versions of IE yet, although I couldn't find any info suggesting this specific issue with recent versions of IE. The fact that Microsoft's documentation indicates it should work has left me puzzled by this behavior. I'm exploring possibilities to figure out what might be missing or if the VM images used for testing code are to blame. Any insights on where I'm going wrong would be greatly appreciated!
UPDATE: My goal is to obtain a comprehensive list of styles currently applied to an element, similar to how cssText
from the object returned by getComputedStyle()
behaves in Chrome - a functionality that seems lacking in Firefox and IE. Specifically, accessing the style.cssText
property of an element in IE retrieves styles from stylesheets, style tags, and inline rules but omits styles manipulated via scripts. While this may be intentional, the question remains: How can I achieve the same outcome as seen with cssText
from a CSSStyleDeclaration object when using getComputedStyle()
in Chrome, but within Internet Explorer and Firefox?