I\'ve got this jquery code and html to work OK for an English language training site.
$(document).ready(function() {
$(\"p\").hover(
function() {
You can add event listeners for the ended and playing events. Also, why creating a audio tag via javascript? I would just create an empty hidden audio tag:
You have two options:
Then add two eventlisteners to it:
var playing = false;
$('#myAudio').on('playing', function() {
playing = true;
// disable button/link
});
$('#myAudio').on('ended', function() {
playing = false;
// enable button/link
});
$("p").click(function (event) {
if(!playing) {
var element = $(this);
var elementID = event.target.id;
var oggVar = (elementID +".ogg");
var audioElement = $('#myAudio')[0];
audioElement.setAttribute('src', oggVar);
audioElement.play();
}
});