Remove a specific inline style with Javascript|jQuery

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

I have the following code in my html:

hello world

7条回答
  •  独厮守ぢ
    2020-12-08 02:10

    I think there is no proper solution to this problem (without changing your markup). You could search and replace the style attribute's value:

    var element = $('#foo');
    element.attr('style', element.attr('style').replace(/font-size:[^;]+/g, '').replace(/font-family:[^;]+/g, ''))
    

    By far the best solution would be to get rid of the inline styles and manage the styles by using classes.

提交回复
热议问题