Reputation:
I want to fire mouseclick sound effect on each click on page.
<audio id='aclick'>
<source src="audio/click.mp3" type="audio/mpeg">
</audio>
$(document).on('click', function(){
document.getElementById("aclick").play();
});
generally it works but it doesn't work on link
element.
Clicking on any <a></a>
element - there is no sound.
example of my link:
<a href='index.php'><img id='logoc' src='img/02.jpg' alt='img'></a>
Upvotes: 3
Views: 1141
Reputation: 5962
You need to attach the event handler to any tags which have click events like below
$("*").on('click',function(){
document.getElementById("aclick").play();
});
And audio tag like below
<audio id='aclick' autoPlay='false' preLoad='auto' >
<source src="audio/click.mp3" type="audio/mpeg">
</audio
Upvotes: 3