I have the following lines of code in my web page - demo/example.
HTML:
<button class="wrong-answer" onclick="showResult(this)">42</button>
<button class="right-answer" onclick="showResult(this)">43</button>
<p id="answer"></p>
JS:
function showResult(b) {
var res = document.getElementById('answer');
if (b.classList.contains('right-answer')) {
res.innerHTML = '<span class="right">right</span>';
}
else {
res.innerHTML = '<span class="wrong">wrong</span>';
}
}
How can I make the <span> tags appear or fade-in (with a duration of 2 seconds) when one of the buttons is selected, display this result (for a duration of 5 seconds) then if possible, removing it again (a duration of 2 seconds)?