Skip to content

Instantly share code, notes, and snippets.

@ichiban
Last active December 31, 2017 14:26
Show Gist options
  • Save ichiban/ba694126f9ba2185b9e5e785391f2b96 to your computer and use it in GitHub Desktop.
Save ichiban/ba694126f9ba2185b9e5e785391f2b96 to your computer and use it in GitHub Desktop.
Toggle Bulma's navbar-burger with delegation
// https://bulma.io/documentation/components/navbar/#navbarJsExample
document.addEventListener('click', function (e) {
if (!e.target || !e.target.matches('.navbar-burger')) {
return;
}
// Get the target from the "data-target" attribute
const target = e.target.dataset.target;
const $target = document.getElementById(target);
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
e.target.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment