Skip to content

Instantly share code, notes, and snippets.

@pinkhominid
Created August 22, 2020 03:05
Show Gist options
  • Save pinkhominid/534a8549b3505a9af1fd16dcc85c6bf9 to your computer and use it in GitHub Desktop.
Save pinkhominid/534a8549b3505a9af1fd16dcc85c6bf9 to your computer and use it in GitHub Desktop.
Simple attribute toggle behavior
import { eventPathTargetMatch } from 'https://gist.githubusercontent.com/pinkhominid/8bd98fa6741fb7327ef91724dc9e5590/raw/8c09c01ea7836f9dcdc0867e5a51851430b703b4/eventPathTargetMatch.js';
document.addEventListener('click', e => {
const target = eventPathTargetMatch(e, 'button[aria-controls]');
if (!target) return;
document
.querySelector(`#${target.getAttribute('aria-controls')}`)
.toggleAttribute(target.value);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment