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

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

If I have the following in my html:

And this in my c

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 15:34

    This can be accomplished in two steps:

    1: select the element you want to change by either tagname, id, class etc.

    var element = document.getElementsByTagName('h2')[0];

    1. remove the style attribute

    element.removeAttribute('style');

提交回复
热议问题