how to play sound with keypress in javascript code example
Example 1: play sound with keydown javascript
document.addEventListener('keydown', function(e) {
if (e.keyCode == 65) {
document.getElementById('audio').play();
}
});
Example 2: play sound with keydown javascript
<audio id="audio" controls style="display:none">
<source src="http://butlerccwebdev.net/support/html5-video/media/soundfile.mp3" type="audio/mpeg"> Your browser does not support the audio element.
</audio>