+ 4
What is best and easy way to use css in js.
I am working on an project which have to change css property with different condition. So i want to use easy way to use css in js file.
15 Answers
+ 7
If you are using jQuery anyways, go for it.
If you did not intend to use jQuery, it depends on the particular task whether it is "worth" it to import jQuery. If your goal for the moment is just to toggle some classes, e.g., you may do that with Javascript as well.
It depends on your goal and experiences.
+ 6
Prepare the css classes, then add to or remove them from the html elements with js.
+ 4
Raja Rawat
Highly I recommend styled components
Which you can write css inside Javascript. It prevents from identifier conflicts by converting each identifier to unique value, also you can pass a css property value as a variable. mostly it uses with ES6 & REAC.JS
https://www.styled-components.com/
+ 2
Johnnie 🎩 yea jQuery
+ 2
There is no need to use jquery at all. Could you explain in what way jquery is the "best" solution?
+ 2
Already noted, and giving heads up on easy and concise way to play with css.
+ 1
If you already know JS, it will also be easy for you to import and implement JQuery; which has “.css(prop,val)” method that you can call literally on any DOM element.
+ 1
Lisa why?
+ 1
Lisa it’s a facade extended from JS to prevent repeated and boilerplate coding.
+ 1
The question is not what jquery is. The question is why jquery would be the "best" solution.
The question does not imply that the OP is looking for a jQuery solution.
+ 1
Ok no prob✋
I think use of css file best option
+ 1
Lisa thanks for information 👍
+ 1
jQuery is concise and versatile. I unfortunately find it visually cluttered and confusing.
The code looks like a stereogram after staring at it after some time.
But if it works for you, go for it.
+ 1
Sony Hossain Thanks👍