Categories
JavaScript Answers

How to override !important style with JavaScript?

Spread the love

Sometimes, we want to override !important style with JavaScript.

In this article, we’ll look at how to override !important style with JavaScript.

How to override !important style with JavaScript?

To override !important style with JavaScript, we can use the setProperty method.

For instance, we write

document.body.style.setProperty('background-color', 'green', 'important');

to call setProperty to change the background color of the body element.

We call it with 'background-color', 'green' and 'important' to make it an !important style.

Conclusion

To override !important style with JavaScript, we can use the setProperty 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 *