Rules

Secret ingredients to quality software

Edit
Info

Do you avoid making changes to individual CSS styles using jQuery?

Last updated by William Yin on 24 Aug 2015 01:08 am (over 5 years ago) See History

We all know that jQuery is very powerful and can do a lot of stuff, including style changes. However, this practice is bad.

Instead of changing the appearance of elements with jQuery, you should use CSS classes. This way you can keep all your CSS in your CSS files, specify different appearances for different classes.

It's OK to use jQuery to add or remove classes and apply your CSS. For this we can use .addClass() and .removeClass() methods.

Tiago AraujoTiago Araujo

We open source. This page is on GitHub