install @buuug7/simplify-switch
package via npm, and then import from @buuug7/simplify-switch/index.css
file.
npm install @buuug7/simplify-switch
<div class="switch"></div>
<div class="switch active"></div>
use javascript
document.querySelectorAll(".switch").forEach(function (node) {
node.addEventListener("click", function (e) {
const t = e.target.closest(".switch");
const active = t.classList.contains("active");
active ? t.classList.remove("active") : t.classList.add("active");
});
});