<audio> src change using javascript

I want to change the src attribute of a tag using javascript and a button:

<audio id="playme" src="" controls="controls">Your browser...</audio> 

And a little further down the page:

 <input type="button" style="font-size: 10px;" OnClick="document.getElementById('playme').src='snd/SOUND.WAV';" value="Listen"> 

It just seems to do nothing. Somebody knows? Thanks a million

Using Firefox 3.6 on Xubuntu 10.10

EDIT : It works in Chrome, but Firefox doesn't like it. Should I report an error? Do you know a way around this?

+6
javascript html5-audio
source share
1 answer

I believe that you should tell the browser to load a new file when the src attribute changes, calling load :

 var playme = document.getElementById('playme'); playme.src='snd/SOUND.WAV'; playme.load(); 
+13
source share

All Articles