Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.15 KB

README.md

File metadata and controls

42 lines (33 loc) · 1.15 KB

simplify switch

npm version npm downloads minified size

Install

install @buuug7/simplify-switch package via npm, and then import from @buuug7/simplify-switch/index.css file.

npm install @buuug7/simplify-switch

Demo examples

Usage

<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");
  });
});