Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda