Domanda

I am trying to figure out the method for switching audio tag source. In this example I am getting the source from a list, however I'm not sure how to do it.

Here is the fiddle: jsfiddle.net/4vrR2/9

Any advice on making it work would be appreciated :)

È stato utile?

Soluzione

To change the attribute you need to specify setAttribute("src",value) instead of src:

http://jsbin.com/zexoweyu/1/edit

function changeSong() {
  var element = document.getElementById("audioPlayer") 
  element.setAttribute("src","magic");
}

PS: To see the change in the DOM open the browser devtools, since JSBin will not reflect the change in the source code tab.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top