How can I erase all inline styles with javascript and leave only the styles specified in the css style sheet?

前端 未结 7 711
一整个雨季
一整个雨季 2020-12-02 14:53

If I have the following in my html:

And this in my c

7条回答
  •  不思量自难忘°
    2020-12-02 15:50

    $('div').attr('style', '');

    or

    $('div').removeAttr('style'); (From Andres's Answer)

    To make this a little smaller, try this:

    $('div[style]').removeAttr('style');

    This should speed it up a little because it checks that the divs have the style attribute.

    Either way, this might take a little while to process if you have a large amount of divs, so you might want to consider other methods than javascript.

提交回复
热议问题