I'm building a quiz app in Angular and I've "moved" the explanation into the question box using replaceWith, but now I need help with hiding the original explanation below the correct answer. replaceWith should occur only when the correct answer is chosen. The explanation has to move when the correct answer is selected to each question in the quiz and at the same time remove the original explanation from below the correct answer. When I advance to the next question, the explanation from the previous question is in the place of the question box but it should be reset to the current question, not sure how to go about doing this. Please see my code below.
<div [hidden]="!isCorrect(option.optionValue)">
<div id="explanation">
Option {{ question.answer }} was correct because {{ question.explanation }}.
</div>
</div>
ngAfterViewInit() {
this.itemFrom = document.getElementById('explanation');
this.itemTo = document.getElementById('question');
}
radioChange(answer) {
this.question.selectedOption = answer;
this.answer.emit(answer);
this.moveExplanation(this.itemFrom, this.itemTo);
if (this.option === this.question.answer && this.question.selectedOption === this.question.answer) {
this.count++;
this.score++;
}
}
moveExplanation(from, to) {
to.replaceWith(from);
}