Skip to content

Instantly share code, notes, and snippets.

@tevko
Created March 28, 2021 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tevko/5ccd2fd623eeba20aef86540e0c3669f to your computer and use it in GitHub Desktop.
Save tevko/5ccd2fd623eeba20aef86540e0c3669f to your computer and use it in GitHub Desktop.
const toggle = document.querySelectorAll(".switch input");
toggle.forEach((el) =>
el.addEventListener("click", (e) => {
const isPressed = el.getAttribute("aria-pressed");
el.setAttribute(
"aria-pressed",
// this part is tricky for humans cause "false" === true, since a non empty string is truthy in js
isPressed === "false" ? "true" : "false"
);
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment