开发者

Check if size has been set with JavaScript in IE

I was wondering if there was a way in JavaScript to check if the size of an element has previously been set? Even though this obviously wont work, this is kind of what I need to happen.

if(element.style.width === undefined)
    element.style.width = 'auto';

I was wondering if this might work due to a non set opacity returning full. Maybe the same applies to...

element.style.width = element.style.width; // If not set then it will set it to default value?

Thanks in advance.

EDIT

Using this code I have managed to get it working in IE8. IE7 and 6 still are not working though, any suggestions?

element[e].style.width = element[e].style.width;
element[e].style.height = element[e].style.height;
if(element[e].currentStyle)
{
    element[e].style.width = element[e].currentStyle.width;
    element[e].style.height = element[e].currentStyle.hei开发者_C百科ght;
}


In IE, you can check an element's width using

var width = element.currentStyle.width;

The default value (i.e. if the width has not been set by any style rule or script) is auto.


Okay, my post sort of dropped of the radar, I eventually fixed it by applying this property.

zoom: 1;

It then worked in IE6, IE7 and IE8.

Thanks anyway.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜