Search code examples
jquerycssinternet-explorer-7internet-explorer-6

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'});

Solution

  • 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.