Skip to content

Instantly share code, notes, and snippets.

@sashadev-sky
Last active June 5, 2020 17:59
Show Gist options
  • Save sashadev-sky/48920de7fc118bca7ac115752414444f to your computer and use it in GitHub Desktop.
Save sashadev-sky/48920de7fc118bca7ac115752414444f to your computer and use it in GitHub Desktop.
// app/assets/javascripts/beeper.js
const audio = new Audio('http://soundbible.com/grab.php?id=1815&type=mp3');
document.addEventListener('click', (event)=>{
let el = event.target;
if (el.matches('.beeper')) {
console.log("beep!");
audio.play();
el.classList.toggle("disabled");
}
});
<!DOCTYPE html>
<html>
<head>
<body>
<button class="beeper">Click me</button>
</body>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment