Remove a specific inline style with Javascript|jQuery

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

I have the following code in my html:

hello world

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 02:21

    For those that aren't using jQuery, you can delete specific styles from the inline styles using the native removeProperty method. Example:

    elem.style.removeProperty('font-family');
    

    Of course, IE < 9 doesn't support this so you'll have to use

    elem.style.removeAttribute('font-family');
    

    so a cross browser way to do it would be:

    if (elem.style.removeProperty) {
        elem.style.removeProperty('font-family');
    } else {
        elem.style.removeAttribute('font-family');
    }
    

提交回复
热议问题