Hey, I wouldn't suggest this method for a couple reasons:
it's going to be less performant than writing CSS in the first place, and it will likely either block page loading or create a jump in styling once the styles are applied.
the separation of concerns. It's usually best practice to separate out your code into different files for HTML/CSS/JS so that you don't have one really long file to look through, plus then you know where to go to debug an issue with one of the pieces!
CSS in JS is a valid thing, but I would use a library built for that so that your code is more performant and follows best practices!
I think you've missed a very important argument why you shouldn't do this at all. What about a client ho has disabled javascript (because reasons)? He/she is able to see your page, but with the wrong styling.
JS is good for doing the extra mile, please use CSS for the things it was intended. We can even make animations and transitions with CSS today!
Good luck :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey, I wouldn't suggest this method for a couple reasons:
CSS in JS is a valid thing, but I would use a library built for that so that your code is more performant and follows best practices!
Hi Ali, Dirk,
I think you've missed a very important argument why you shouldn't do this at all. What about a client ho has disabled javascript (because reasons)? He/she is able to see your page, but with the wrong styling.
JS is good for doing the extra mile, please use CSS for the things it was intended. We can even make animations and transitions with CSS today!
Good luck :)