DEV Community

[Comment from a deleted post]
Collapse
 
antonfrattaroli profile image
Anton Frattaroli • Edited

Vanilla sounds good until you try it. You might be all like 'el.classList.add(className);' is easy! But then that crashes when you have an empty className string so you either need to refactor to use the ugly 'el.className += ' ' + className;' or write a function that checks for empty strings before adding the class. And all the while there are utility libs like jquery slim or ampersand that already do that with thorough testing, and cdns to host them or to import to a webpack bundle.

Collapse
 
belhassen07 profile image
Belhassen Chelbi

I agree jQuery may sometimes be saving a lot of work and jQuery slim may help in the performance, but still it doesn't solve the spaghetti code part, and yes I agree vanilla alone is tricky and I've used a lot but when checking yourself and doing the work will give you a lot of benefits , we may even create our own very little libraries for the repeating parts so we won't include a whole library to make a small app. So yes, jQuery may solve problems and may cause a lot of them too so depending on the project, we need to decide whether we need it or not.
Thanks for sharing your ideas Anton ♥

Collapse
 
antonfrattaroli profile image
Anton Frattaroli

I see where you're coming from but then everyone is reinventing the wheel. Take ampersand for instance, you can choose to import only the addClass module, and it's tested and on npm, which is going to save a ton of time.

 
belhassen07 profile image
Belhassen Chelbi

I didn't know that , I'll check it out, thanks again Anton ♥