1var element = document.getElementById('element');
2element.classList.add('class-1');
3element.classList.add('class-2', 'class-3');
4element.classList.remove('class-3');
1Installation:
2yarn add classnames or npm i classnames
3
4Usage:
5classNames('foo', 'bar'); // => 'foo bar'
6classNames('foo', { bar: true }); // => 'foo bar'
7classNames({ 'foo-bar': true }); // => 'foo-bar'
8classNames({ 'foo-bar': false }); // => ''
9classNames({ foo: true }, { bar: true }); // => 'foo bar'
10classNames({ foo: true, bar: true }); // => 'foo bar'
11
12// lots of arguments of various types
13classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
14
15// other falsy values are just ignored
16classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
17
18TypeInstallation:
19yarn add @types/classnames