1

Just a few days ago, thanks to Google, I landed here and learnt how to make a spoiler in HTML. So the following code works:

<div id="spoiler" style="display:none">
ADD YOUR HIDDEN CONTENT HERE
</div>
<button title="Click to Show/Hide Content" type="button" onclick="if(document.getElementById('spoiler') .style.display=='none') {document.getElementById('spoiler') .style.display=''}else{document.getElementById('spoiler') .style.display='none'}">Show/Hide</button>

But, I would like the spoilered content to appear under the button when I reveal it, whereas now it appears above the button. Is this possible?

MickG
  • 3,216
  • 2
  • 14
  • 22

1 Answers1

3

Simply do this :

<button title="Click to Show/Hide Content" type="button" 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">
ADD YOUR HIDDEN CONTENT HERE
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415