Categories
JavaScript Answers

How to dynamically remove a stylesheet from the current page with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *