Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Browser doesn't update when changing CSSStyleRule with JS

It seems like when modifying the CSS properties of elements when using JS methods (CSSStyleSheet, with insertRule or deleteRule, or CSSStyleRule.style.setProperty()), the underlying CSS has been updated, but the page itself not not reflect the changes.

The changes are only realised upon some reflow trigger, say after I've changed the attribute of the element, even if it's an invalid one.

May be related to this question: What are the conditions under which a browser will re-assess and reapply CSS selectors and styles?

What is the recommended way to modify CSS using JS? Apart from changing class strings, or a hacky way to insert and delete attributes?

Note: Testing on Edge / Chromium

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After reading your post, I'm not sure if you are aware of these simple ones:

element.style = stylestring (IE: "display:block; color:red;")

or

element.setAttribute('style', stylestring)

These will be treated as inline-styles. So changed properties will take priority over the external css and the effect will be immediate.

Now, is it the recommended way? That's a tough one, I'll let others answer this question, I'm not really a W3C guy...

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!