I'm not 100% sure what you're trying to achieve, but if you need to add animations on an element(s) with JS after some event, consider the following way:
Define styles with css like
.hidden{...}.animate{...}
Add/remove CSS classes with animations when necessary with DOM API: document.querySelectorAll('.hidden').classList.add('animate')
Thanks for writing but I just wanted to update an element's CSS with JS. no more new class I wanted to Edit animation-duration value from JS. I resolve it thx
With CSSStyleSheet, what is the best way to replace a rule? I see insertRule seems to take an index, if I re-use that same index then that rule will be replaced? The reason is that I want to allow the endusers to change some styles via a UI, then quickly update that to the specific element.
I'm here to share my knowledge with you and improve my English skills. If you see that I made a mistake somewhere, I will be happy if you let me know about it. :)
I don't think you ever need to use insertRule in your day-to-day job unless you hit some performance bottleneck when working with styles. I think optimizations with insertRule are useful for libraries (like styled-components), but add unnecessary complexity when developing regular websites or apps.
I am a Web Full Stack Developer and designer based out of Rabat, MA. I love building apps that solve real-world problems, and that are delightful to use. My specialities include JavaScript, React JS
hey can you maybe help me ?
I have some things like this and I just want to Update the hidden class but I Update Complete Style
var style = document.getElementById('style');
var counter = parseInt(60);
I'm not 100% sure what you're trying to achieve, but if you need to add animations on an element(s) with JS after some event, consider the following way:
document.querySelectorAll('.hidden').classList.add('animate')
Thanks for writing but I just wanted to update an element's CSS with JS.
no more new class I wanted to Edit animation-duration value from JS.
I resolve it thx
With CSSStyleSheet, what is the best way to replace a rule? I see insertRule seems to take an index, if I re-use that same index then that rule will be replaced? The reason is that I want to allow the endusers to change some styles via a UI, then quickly update that to the specific element.
3 veeery interesting. thanks for the tip ;)
It's something I'm looking for. Thanks a lot!
really great post i like it
Hi :D
I just wondered if using insertRule for performance or not and I found this article. Thanks !
But how it differ?
I don't think you ever need to use
insertRule
in your day-to-day job unless you hit some performance bottleneck when working with styles.I think optimizations with
insertRule
are useful for libraries (likestyled-components
), but add unnecessary complexity when developing regular websites or apps.developers.google.com/web/updates/...
style.setContent bug ❌
Thanks man for sharing, I was looking for something like this long ago
great
this is really helpful :)