Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
jQuery

Add and Remove Classes in jQuery

Manage CSS classes with addClass, removeClass, toggleClass, and hasClass.

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')) { /* ... */ }

Leave a reply

Your email address will not be published. Required fields are marked *