title: Listen for when an HTML5 Audio element stops playing
body: <p>I need to call a function when an HTML5 audio element stops playing. Specifically the function will reset the seek bar and change the pause icon to a play icon.</p>
  
  <p>Here's my JavaScript:</p>
  
  <pre><code>var audio = document.getElementById('audio');
  
  audio.addEventListener('ended', stopAudio);
  
  function stopAudio() {
      audio.stop();
      $('.play-pause .play').show();
      $('.play-pause .pause').hide();
  }
  </code></pre>
  
  <p>.. only the code inside is not executing once called. The audio is playing successfully and ending successfully, it's just not calling my function. What am I missing?</p>