When making changes to CSS properties of elements using JS methods like CSSStyleSheet
, insertRule
, deleteRule
, or CSSStyleRule.style.setProperty()
, I noticed that the underlying CSS is updated but the page does not reflect these changes immediately.
The changes only take effect after triggering a reflow, such as modifying an attribute of the element, even if it's invalid.
This issue might be related to the question posed here: What are the conditions under which a browser will re-assess and reapply CSS selectors and styles?
What is the best practice for modifying CSS with JavaScript? Is there a recommended method besides manipulating class strings or using unconventional attribute insertion and deletion techniques?
Note: Testing conducted on Edge / Chromium browsers