How to dynamically remove a stylesheet from the current page

后端 未结 9 2125
无人共我
无人共我 2020-12-04 12:17

Is there a way to dynamically remove the current stylesheet from the page?

For example, if a page contains:



        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 12:50

    If you know the ID of the stylesheet, use the following. Any other method of getting the stylesheet works as well, of course. This is straight DOM and doesn't require using any libraries.

    var sheet = document.getElementById(styleSheetId);
    sheet.disabled = true;
    sheet.parentNode.removeChild(sheet);
    

提交回复
热议问题