spoiler with javascript

JavaScript

function button(spnum){
  var button = document.getElementById('spoiler_' + spnum);
  var content = document.getElementById('content_' + spnum);
    if(content.className == 'hidden'){
      content.className = "visible";}
    else if(content.className == 'visible'){
      content.className = "hidden";}
}

CSS

.hidden {
display: none;
}
.visible {
display: block;
margin: 5px;
}
.spoiler-btn {
padding:4px;
}

HTML

<button id="spoiler_1" class="spoiler-btn" onclick="button(1)">First Spoiler</button>
<div id="content_1" class="hidden">
  First spoiler content
</div>
</br>
<button id="spoiler_2" class="spoiler-btn" onclick="button(2)">Second Spoiler</button>
<div id="content_2" class="hidden">
  Second spoiler content
</div>
<br>          
<button id="spoiler_3" class="spoiler-btn" onclick="button(3)">Third Spoiler</button>
<div id="content_3" class="hidden">
  Third spoiler content
</div>

Demo