My Next button on my quiz breaks, if I answer up to a particular question then return back a few questions and then proceed to continue the quiz. After you hit next you won't be able to proceed until you re-select an answer even though there already is an answer selected.
Full JSFiddle:
JSFiddle Link
The issue is with this: (line 121 JSFiddle)
btnNxt.onclick = function() {
if(document.getElementById('btnNxt').hasAttribute('disabled')){
return false;
}
document.getElementById('btnNxt').setAttribute('disabled', true);
buildQuiz(page + 1)
}
When the next button is clicked it disables the attribute. I believe I need to wrap
document.getElementById('btnNxt').setAttribute('disabled', true);
Within an if statement that checks if an answer has already been provided or if it's on a new question
I tried to create something to check if there was a class with the value myAns before setting the attribute but didn't have much success
var element = document.getElementsByClassName('btnAns');
for(var i = 0; i < element.length; i++){
if(element[i].classList.contains('selAnswer')) {
document.getElementById('btnNxt').setAttribute('disabled', true);
break;
} else {
document.getElementById('btnNxt').removeAttribute('disabled');
}
console.log(element[i].classList.contains('selAnswer'));
}