+ 2
Why use JS to control the style of HTML elements instead of CSS?
4 Réponses
+ 5
you can use css indeed, but if you want to edit the color while still in the same session, you need javascript to change the css during the session
+ 5
There are some cases where you need to change some property after an event, and there JS does a good job. In any case, there are other alternative practices on this (like preprocessors that compile from JS to CSS and ways to use JS for absolutely everything)
http://postcss.org/
https://medium.freecodecamp.org/css-in-javascript-the-future-of-component-based-styling-70b161a79a32
0
Use JS to change CSS based on specific activities by the user.
0
CSS is static.
You need JavaScript to have a dinamic and interactive web site.
The JavaScript will change CSS proprerty based on what user do.
"if he click on this place the color will change"
"if he push the right arrow, the car will move to the right"
You also can make an abimation with JavaScript.
with CSS you make static images
With Javascript you make animations or games, etc.