开发者

In IE7 and IE6, setting element.style['display'] = 'inherit' thows an exception

开发者 https://www.devze.com 2023-01-13 02:43 出处:网络
What\'s a good workaround to this IE bug that would still allow me to set the display style of an HTML element to \'inherit\' in IE7 or IE6 using javascript?

What's a good workaround to this IE bug that would still allow me to set the display style of an HTML element to 'inherit' in IE7 or IE6 using javascript?

    var el = document.getElementById('someElementID');
    if (!el) return false;
    try {
        var displayValue = 'inherit';
        //the next line throws exception in IE7 and IE6
        // when displayValue = 'inherit'
        // but not for other legit values like 'none', 'block', 'inline' or even ''
        el.style['display'] = displayValue;
    } catch (e) {
        alert(e.message);
    }

Assume that I don't want to set 开发者_如何学Govisible: hidden, position:absolute it out of view or z-index it under something else.


A lot of values for the display property was added in CSS 2, and inherit is one of them. Older browsers don't support these new values. You can compare the possible values in CSS 1 and CSS 2.

Even if you could set the value, it's useless as the browser doesn't know what to do with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消