开发者

don't work: remove style attribute or change width\height css property via jquery in IE6\IE7\IE8

开发者_高级运维How remove style attribute or change width\height CSS property via jQuery in IE6\IE7\IE8?

Don't work:

$(e).css({'width': '', 'height': ''});
$(e).removeAttr('style');
e.removeAttribute('style');

Update:

e is native object of DOM. Firebug tell me that element exists

In first function i add width\height, in second remove.

in other browser all ok

Don't work:

$(e).css({'width': 'auto', 'height': 'auto'});


I think you want to set the width and height properties to their "initial value".

The initial value for both properties is auto, so this will work:

$(e).css({
    'width': 'auto',
    'height': 'auto'
});

I tested this in IE6, and it works as expected: http://jsfiddle.net/BNrgF/


So you want to set the width and height back to the whatever is defined in css?

In theory what you do should work (unless there's some jquery specific issues which I'm not aware of), but I think IE won't accept empty string as a valid value and may keep the value unchanged.

The most foolproof way to do it, is to store the original value before you change it the first time (unless this is a generic effect that should be applied to an undefined amount of elements, this should not be too hard) and set it back to that value instead of clearing it.

If the original value is a calculated value such as percentage (of the screen width etc.) you may have to recalculate it or set it to a hardcode percentage value since you may not be able to get the original css value, only the calculated pixel value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜