Skip to content

Instantly share code, notes, and snippets.

@code-for-coffee
Created May 15, 2015 01:05
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 code-for-coffee/8497ea51a0ee8fd9f2e4 to your computer and use it in GitHub Desktop.
Save code-for-coffee/8497ea51a0ee8fd9f2e4 to your computer and use it in GitHub Desktop.
Play audio
<audio id="kablam!">
<source src="/assets/kablam.mp3" type="audio/mpeg">
</audio>
<button id="playSoundBtn">Kablam!</button>
// selector: `button` with an id attribute of `playSoundBtn`
$('#playSoundBtn').on('click', function(event) {
// get the audio element by Id and play() it
document.getElementById('kablam!').play();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment