MCPcopy Create free account
hub / github.com/flyfloor/react-component / toggleClass

Function toggleClass

component/util/dom.js:1–9  ·  view source on GitHub ↗
(el, className)

Source from the content-addressed store, hash-verified

1export function toggleClass(el, className){
2 if (el && el instanceof Node && className) {
3 let str = el.className;
4 const index = str.indexOf(className);
5 el.className = index === -1 ?
6 `${str} ${className}`
7 : str.slice(0, index) + str.slice(index, className.length);
8 }
9}
10
11export function removeClass(el, className){
12 if (!el || !className) return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…