Eliminate the null value for "selection" in relation to #myBtnC. Remove this segment from your code.
Implement this adjustment and inform me of any results.
function onSelect(e) {
var selection = e.currentTarget;
var preSelection = selection;
var questionId = e.currentTarget.className;
var currentQuestion = questions.find(function(q) {
return q.questionId == questionId
});
$("#myModal").modal();
document.getElementById("m_q").innerHTML = "<h3>" + currentQuestion.question + "</h3>";
document.getElementById("m_o").innerHTML = "<h2>" + selection.firstElementChild.innerText + "</h2>";
$("#myBtnC").click(function() {
if (!selection) {
selection = preSelection;
}
selection.setAttribute('class', 'question1');
selection = null;
$('#myModal').modal('hide');
});
$("#myBtnO").click(function() {
if (currentQuestion.locked) {
alert("Question already answered");
}
if (!selection) {
selection = preSelection;
} else if (currentQuestion.answer === selection.firstElementChild.innerText) {
alert("Correct!!!");
} else {
alert("Incorrect...");
}
selection = null;
$('#myModal').modal('hide');
});
}
This revised version functions optimally. Customize it as needed based on your specifications.