Add and Remove Classes in jQuery — a practical guide to jQuery addClass removeClass with clear examples you can reuse in real projects.
jQuery Tutorial Series (39/101). Prefer one article? Read the complete jQuery tutorial.
Short description
Drive UI state with classes rather than inline styles when possible.
Classes
$('#btn').addClass('primary');
$('#btn').toggleClass('is-open');
if ($('#btn').hasClass('primary')) { /* ... */ }