+ 2

Why use JS to control the style of HTML elements instead of CSS?

19th Jul 2018, 12:20 AM
Ikboljon Sobirov
Ikboljon Sobirov - avatar
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
19th Jul 2018, 12:23 AM
Roel
Roel - avatar
+ 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
19th Jul 2018, 4:14 AM
Mickel
Mickel - avatar
0
Use JS to change CSS based on specific activities by the user.
19th Jul 2018, 2:13 AM
Paul Grasser
Paul Grasser - avatar
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.
19th Jul 2018, 6:12 AM
DDD
DDD - avatar