How do I unset an element's CSS attribute using jQuery?

前端 未结 6 1872
北海茫月
北海茫月 2020-12-05 03:30

If I set a CSS value on a specific element using:

$(\'#element\').css(\'background-color\', \'#ccc\');

I want to be able to unset that elem

6条回答
  •  猫巷女王i
    2020-12-05 04:12

    For what it's worth this appears not to work in IE 8 for 'filter,' I had to use this (in fadeIn callback):

    $(this).attr('style', $(this).attr('style').replace(/\bfilter:\s*;*/, ''));

    Obviously, I had need to remove an empty inline filter declaration so the CSS could take effect; there were other inline rules so I couldn't just remove the style attribute.

提交回复
热议问题