Show/Hide Div using JavaScript

Categories: HTML&JS; Tagged with: ; @ August 7th, 2012 23:01

Show/Hide div by style.block using JavaScript.

the href button:

<a href="#" onclick="switchDiv()">SwitchDiv</a>

The js:

switchFlag = true;
function switchDiv() {
// alert("clicked");
switchFlag = !switchFlag;

var div1 = document.getElementById('div1');

var div2 = document.getElementById('div2');

if(switchFlag) {
div1.style.display="block";
div2.style.display="none";

}else {
div1.style.display="none";
div2.style.display="block";
}
}

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.