Hello,
The code below is called when a user clicks a 'Submit' button. The problem is the line highlited below, each time they click it adds an additional listener so the event fires twicethe second time, three times the third time, etc.
What is the best way to avoid adding unwanted listeneres like this?
Code:
function checkAnswer()
{
alert(chosenAnswer);
if(chosenAnswer == correctAnswer)
{
var xmlFeedBack = "";
$(questionArr[questionIndex]).find('answer').each(function(){
if($(this).find('aText').text() == chosenAnswer)
{
xmlFeedBack = $(this).find('feedback').text();
alert(xmlFeedBack);
}
});
$("#feedback").html('<img src="../js_know_check/course_assets/kcbtnsprite.png" /><br/>' + xmlFeedBack + "<br/><br/>Click This Message Box to Continue.");
questionIndex++;
$("#feedback").click(function (evt) {alert("You clicked the message box! Great");displayQuestion()});
numCorrect++;
}
}