button on click array and parameter

div show up on button click

by stackmanoz

HTML

<button>para 1</button><br>
<div>one one one one one one one one one one one one one one one one one oneone one one one one one one one one one  </div><br>
<button>para2</button><br>
<div>two two two two two two two two two two two two two two two two two twotwo two two two  </div><br>
<button>para3</button><br>
<div>three three three three three three three three three three three three three three three three </div><br>

CSS

div {display:none;}

JavaScript

button = document.getElementsByTagName('button');
para = document.getElementsByTagName('div');

function show(x) {
    para[x].style.display = 'block';
    button[x].onclick = function() {
        hide(x);
    }
}

function hide(x) {
    para[x].style.display = 'none';
    button[x].onclick = function() {
        show(x);
    }
}

button[0].onclick = function() {
    show(0);
}

button[1].onclick = function() {
    show(1);
}
button[2].onclick = function() {
    show(2);
}