Sometimes, we want to dynamically remove a stylesheet from the current page with JavaScript.
in this article, we’ll look at how to dynamically remove a stylesheet from the current page with JavaScript.
How to dynamically remove a stylesheet from the current page with JavaScript?
To dynamically remove a stylesheet from the current page with JavaScript, we call the remove
method.
For instance, we write
document.querySelector('link[href$="something.css"]').remove();
to select the link element with href attribute that includes something.css with querySelector
.
Then we call remove
to remove the element from the DOM.
Conclusion
To dynamically remove a stylesheet from the current page with JavaScript, we call the remove
method.