DEV Community

Discussion on: Set CSS styles with javascript

Collapse
 
karataev profile image
Eugene Karataev

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 {
...
}
Enter fullscreen mode Exit fullscreen mode
  • Add/remove CSS classes with animations when necessary with DOM API: document.querySelectorAll('.hidden').classList.add('animate')
Collapse
 
mzahraei profile image
Ardalan

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