I want to bind a listener to all audio tags (including dynamically added ones) currently on the page that triggers when the user clicks the play button. I was trying it like:
$(document).on("play", "audio", function () {
alert("here");
});
But it doesn't work. I know I can do it the pure JS way. I could probably do something like:
var audioElements = $('audio')
for(i=0;i<audioElements.length;++i) {
audioElements[i].addEventListener('play', function(){
alert("here");
}
}
But a nice JQuery solution would be preferable. Can't find anything online regarding this.
$('audio').on("play", function ()works if called after the audio element has been loaded. If this happens at page loading this onplay can be added to window.onload otherwise a plugin or a test every tot time must run to check for the newly loaded audio......This is all my help. – gaetanoM Dec 16 '15 at 20:34