classico
A tiny (242B) shim for when
Element.classList
cannot be used~!
This module exposes three module definitions:
- ES Module:
dist/classico.mjs
- CommonJS:
dist/classico.js
- UMD:
dist/classico.min.js
Install
$ npm install --save classico
Usage
; const $ = documentquerySelector; const isOpen = 'menu__open'; { ;}; { ;};
API
has(node, str)
Returns: Boolean
Checks if the Element's className
contains the class value – akin to Element.classList.contains()
.
add(node, ...str)
Returns: undefined
Add the class value(s) to the Element's className
– akin to Element.classList.add()
.
Note: Classico will not append a className if the Element already contains it.
let elem = documentbody; // add one classclassico; // add multiple classesclassico;//=> Only 'bar' & 'baz' were added this time!
remove(node, ...str)
Returns: undefined
Remove the class value(s) to the Element's className
– akin to Element.classList.remove()
.
let elem = documentbody; // remove one classclassico; // remove multiple classesclassico;
toggle(node, str, force)
Returns: Boolean
Toggles the existence of a class for an Element – akin to Element.classList.toggle()
.
When force
is not defined, the str
value will be added if not already and removed if it existed.
If force
is defined and truthy, the str
value will be added.
If force
is defined and falsey, the str
value will be removed.
Returns true
if the class was successfully added to the Element.
Returns false
if the class was removed from the Element's className
value.
License
MIT © Luke Edwards