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.