Here is a demo for the CSS solution: http://jsfiddle.net/yf3e5bhv/
The advantage of this approach is that your template is declarative. You could make a plain HTML page of each state of your application. In my opinion this greatly aids development and maintenance.
HTML
<input type="button" value="toggle" id="button" /><br /><br />
<div id="left"></div><div id="right"></div>
CSS
#left, #right {
width: 50%;
background-color: #ff0000;
height: 50px;
float: left;
}
#right {
background-color: #00ff00;
}
body.hide-right #right {
display: none;
}
body.hide-right #left {
width: 100%;
}
JS
var state = false;
document.getElementById("button").addEventListener("click", function () {
var classname = "";
if (state === false) {
classname = "hide-right";
}
document.body.className = classname;
state = !state;
});
You can significantly reduce this code if you use a library like jQuery:
$("#button").on("click", function () {
$(document.body).toggleClass("hide-right");
});