How to dynamically remove a stylesheet from the current page

后端 未结 9 2112
无人共我
无人共我 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:38

    I found this page whilst looking for a way to remove style sheets using jquery. I thought I'd found the right answer when I read the following

    If you know part of the url then you can remove just the one you're looking for: $('link[rel=stylesheet][href~="foo.com"]').remove();"

    I liked this solution because the style sheets I wanted to remove had the same name but were in different folders. However this code did not work so I changed the operator to *= and it works perfectly:

    $('link[rel=stylesheet][href*="mystyle"]').remove();
    

    Just thought I'd share this in case it's useful for someone.

提交回复
热议问题