Skip to content

Instantly share code, notes, and snippets.

@RussellJapheth
Created February 11, 2026 17:03
Show Gist options
  • Select an option

  • Save RussellJapheth/3a66b85de69dcd086e660b28f4e3fda9 to your computer and use it in GitHub Desktop.

Select an option

Save RussellJapheth/3a66b85de69dcd086e660b28f4e3fda9 to your computer and use it in GitHub Desktop.
<button
class="btn btn-primary"
data-user-id="42"
data-role="admin"
>
View
</button>
<script>
const button = document.querySelector('.btn.btn-primary');
button.addEventListener('click', (event) => {
const { userId, role } = event.currentTarget.dataset;
console.log(userId); // "42"
console.log(role); // "admin"
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment