I have the code to launch an event when pressing a key.
$(document).keydown(function(e){
if (e.keyCode == 37) {
alert( "left pressed" );
return false;
}
});
I was wondering how can I launch a sound
in my html I have this :
<audio id="sound1" src="images/step-1/iphone.mp3"></audio>
<audio id="sound2" src="images/step-1/iphone.mp3"></audio>
<div id="pad">
<img src="images/step-1/tsonga.jpg" onclick="document.getElementById('sound1').play()"/>
<img src="images/step-1/federer.jpg" onclick="document.getElementById('sound1').play()"/>
</div>
Like this, but it doesn't work :/
$(document).keydown(function(e){
if (e.keyCode == 37) {
getElementById('sound1').play()
return false;
}
});
Thank you for your help !