Remove a specific inline style with Javascript|jQuery

前端 未结 7 2125
走了就别回头了
走了就别回头了 2020-12-08 01:46

I have the following code in my html:

hello world

7条回答
  •  旧巷少年郎
    2020-12-08 02:08

    My suggestion would be to stay away from setting this stuff using inline styles. I would suggest using classes and then using jQuery to switch between them:

    CSS:

    #foo{ font-size:11pt; font-family:arial; color:#000; }
    #foo.highlight {text-align:center; font-size:14pt; font-family:verdana; color:red}
    

    HTML:

    hello world

    Javascript:

    $('#foo').removeClass('highlight');
    $('#foo').addClass('highlight');
    

提交回复
热议问题