+ 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.

13th Apr 2023, 5:59 PM
Raja Rawat
Raja Rawat - avatar
16 Antworten
+ 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.
14th Apr 2023, 11:05 AM
Lisa
Lisa - avatar
+ 6
Prepare the css classes, then add to or remove them from the html elements with js.
13th Apr 2023, 6:10 PM
Lisa
Lisa - avatar
+ 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/
13th Apr 2023, 6:08 PM
Yasin Rahnaward
Yasin Rahnaward - avatar
+ 2
Johnnie 🎩 yea jQuery
14th Apr 2023, 10:38 AM
Raja Rawat
Raja Rawat - avatar
+ 2
There is no need to use jquery at all. Could you explain in what way jquery is the "best" solution?
14th Apr 2023, 10:39 AM
Lisa
Lisa - avatar
+ 2
Already noted, and giving heads up on easy and concise way to play with css.
14th Apr 2023, 10:49 AM
Johnnie 🎩
Johnnie 🎩 - avatar
13th Apr 2023, 6:54 PM
Tibor Santa
Tibor Santa - avatar
+ 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.
14th Apr 2023, 10:36 AM
Johnnie 🎩
Johnnie 🎩 - avatar
+ 1
Lisa why?
14th Apr 2023, 10:42 AM
Raja Rawat
Raja Rawat - avatar
+ 1
Lisa it’s a facade extended from JS to prevent repeated and boilerplate coding.
14th Apr 2023, 10:42 AM
Johnnie 🎩
Johnnie 🎩 - avatar
+ 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.
14th Apr 2023, 10:47 AM
Lisa
Lisa - avatar
+ 1
Ok no prob✋ I think use of css file best option
14th Apr 2023, 10:52 AM
Raja Rawat
Raja Rawat - avatar
+ 1
Lisa thanks for information 👍
14th Apr 2023, 2:37 PM
Raja Rawat
Raja Rawat - avatar
+ 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.
15th Apr 2023, 5:05 AM
Bob_Li
Bob_Li - avatar
+ 1
Sony Hossain Thanks👍
15th Apr 2023, 3:35 PM
Raja Rawat
Raja Rawat - avatar