In my javascript code, I have the following line:
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(oElm).getPropertyValue(strCssRule);
} // ...
This code is used to retrieve a CSS value of a node (e.g. strCssRule = 'color'
). It works in Firefox but only works on simple examples in Chrome on a static page. When I try to integrate it into my complex application, all fields of the returned CSSStyleDeclaration
are null.
The node oElem
is selected using jQuery (
oElem = $(my_selector).empty().get(0));
). The main difference between the working example and my application is that the node has not yet been added to the DOM when the computation takes place (the full HTML is still being generated).
I even tried explicitly setting the CSS in the HTML declaration (e.g. my node is
<div style="width:100px;"></div>
), but the CSSStyleDeclaration object remains empty.
Edit: As CBroe mentioned, the issue arises because the element is not linked to the DOM yet. The browser's implementation determines how it handles this scenario. Although Firefox was able to make it work, I will need to find an alternative solution.