I have ten of these buttons and answers with the only difference between each one being the answer:
Example:
<div class="showhim">
<button class="answerbtn" onclick="revealAnswersFunction()">Click/Tap To Reveal Answers:</button>
<div class="showme" style="display:none">1D, 2C</div>
</div>
<div class="showhim">
<button class="answerbtn" onclick="revealAnswersFunction()">Click/Tap To Reveal Answers:</button>
<div class="showme" style="display:none">1A, 2D</div>
</div>
<div class="showhim">
<button class="answerbtn" onclick="revealAnswersFunction()">Click/Tap To Reveal Answers:</button>
<div class="showme" style="display:none">1B, 2B</div>
</div>
Now what I want is that if the user clicks a button, the relevant answer will be revealed. Currently, it is doing this but there is a catch, it displays all answers which is not what I want. I want it so that dependent on which button I click, it only reveals the answer for that one and the other answers are not displayed.
How can the code be manipulated to incorporate what I am guessing is some soft of loop to retrieve the button that has been clicked and display the corresponding answer and hide all the other answers?
var answers = document.getElementsByClassName("showme");
var revealAnswers = document.getElementsByClassName("answerbtn");
function revealAnswersFunction() {
if (answers.style.display === "none") {
answers.style.display = "inline-block";
} else {
answers.style.display = "none";
}
}