javascript - currentStyle in IE is null - Stack Overflow

I am trying to caculate the current style of an element:function cssIsLoaded(c) {if (window.getComputed

I am trying to caculate the current style of an element:

function cssIsLoaded(c) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(c, null).display === "none";
    }
    else if (c.currentStyle) {

    }

    return true;
}

(function() {
    var cssload = document.createElement("div");
    cssload.className = "_css_loaded";
    checkLoaded();

    function checkLoaded() {
        if (!cssIsLoaded(cssload)) setTimeout(function() {
            checkLoaded();
        }, 20);
        else blalbalblbalbalablbal();
    }
})();

IE doesnt get into the 2nd condition, c.currentStyle is null... why is that?

I am trying to caculate the current style of an element:

function cssIsLoaded(c) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(c, null).display === "none";
    }
    else if (c.currentStyle) {

    }

    return true;
}

(function() {
    var cssload = document.createElement("div");
    cssload.className = "_css_loaded";
    checkLoaded();

    function checkLoaded() {
        if (!cssIsLoaded(cssload)) setTimeout(function() {
            checkLoaded();
        }, 20);
        else blalbalblbalbalablbal();
    }
})();

IE doesnt get into the 2nd condition, c.currentStyle is null... why is that?

Share Improve this question edited Nov 10, 2010 at 12:37 Andy E 345k86 gold badges481 silver badges451 bronze badges asked Nov 10, 2010 at 10:13 HimberjackHimberjack 5,80218 gold badges73 silver badges121 bronze badges 3
  • 1 Where are you calling cssIsLoaded()? What element are you passing? Can you create an example at jsfiddle? – Andy E Commented Nov 10, 2010 at 10:17
  • I am passing a DIV I just created. i call the function once its JS is loaded in <head> in the site. (it is called right after i created that DIV – Himberjack Commented Nov 10, 2010 at 10:30
  • please show exactly how you are passing it. That is most likely where the error is. – Pekka Commented Nov 10, 2010 at 10:31
Add a ment  | 

1 Answer 1

Reset to default 7

An element doesn't get its currentStyle property populated until it's added to the document, which makes some sense: until the element's been added to the document, the browser cannot know which existing style rules will apply to it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745091710a4610731.html

相关推荐

  • javascript - currentStyle in IE is null - Stack Overflow

    I am trying to caculate the current style of an element:function cssIsLoaded(c) {if (window.getComputed

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信