I have such a small javascript code (I use it in Markdown):
<button title="Click to show answer" type="button" class="btn btn-primary"
onclick="if(document.getElementById('spoiler') .style.display=='none')
{document.getElementById('spoiler') .style.display=''}
else{document.getElementById('spoiler') .style.display='none'}">
show/hide
</button><div id="spoiler" style="display:none">
***
Hidden Text
***
</div>
The problem is that if I want to make several buttons on one page to hide the text, then I need to rename spoiler to spoilerN 4 times
Questions:
(Minimum) Is it possible to compactly output Id to a separate variable in this piece of code?
(Maximum) Is it possible to automatically generate a variable? So that the code itself reuses the variable every time a new button is declared?