What am I doing wrong here? (see JS Fiddle: http://jsfiddle.net/55aJt/6/)
<audio id="myAudio" src="" controls></audio>
Object
var allQuestions = [{
question: "http://www.w3schools.com/html/horse.mp3",
choices: ["3rd", "5th", "4th"],
correctAnswer: 2
},
Function
function setHeader(questionNum) {
var questionHeaderEl = document.getElementById("myAudio").src;
questionHeaderEl.innerHTML = allQuestions[questionNum].question;
}
var questionHeaderEl = document.getElementById("myAudio").src;
questionHeaderEl.innerHTML = allQuestions[questionNum].question;
with above code you are creating a var
for element's src
value then you are trying change innerHtml
of that src
value. It should be like this:
var questionHeaderEl = document.getElementById("myAudio");
questionHeaderEl.src = allQuestions[questionNum].question;