Skip to content

Instantly share code, notes, and snippets.

@leogono
Created August 19, 2020 09:52
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 leogono/9c0ce0eb00e34aad34ed76f61ee2ae63 to your computer and use it in GitHub Desktop.
Save leogono/9c0ce0eb00e34aad34ed76f61ee2ae63 to your computer and use it in GitHub Desktop.
button click js listener
// HTML
// <a href="javascript:void(0)" id="click-this">Click this</a>
let button = document.getElementById('click-this');
button.addEventListener('click', function(ev) {
onClick();
});
function onClick() {
alert('Button clicked');
//or do something...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment