Skip to content Skip to sidebar Skip to footer

Adding Event Listener To Audio Html5 Tag In Javascript

Hi I'm creating a new audio tag element in Javascript this is the code: var audio = document.createElement('audio'); audio.setAttribute('id','myid'); audio.setAttribute('autoplay',

Solution 1:

try:

audio.addEventListener('ended', foo);

This is the correct and standard method to add event listeners.

Solution 2:

First, make sure whether audio element has the event before you use it, suppose the HTMLAudioElement is audio, you can test it like this audio.hasOwnProperty('onended')

Based on my browser, it doesn't support.

Post a Comment for "Adding Event Listener To Audio Html5 Tag In Javascript"