Remove a specific inline style with Javascript|jQuery

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

I have the following code in my html:

hello world

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

    From what I can see you really need two different styles for the paragraph. It might be easier to set those up in CSS and then just use jQuery to remove / add as you need:

    #styleOne { color: red; font: normal 14pt Verdana; text-align: center; }
    
    #styleTwo{ color: #000; font: normal 11pt Arial; text-align: center; }
    

    Your initial html will look like:

    hello world

    And then to revert to styleTwo in jQuery

    $('p#styleOne').removeClass('styleOne').addClass('styleTwo');
    

提交回复
热议问题