Switch html with assigning the innerHTML
<html>
<head>
<title>Overflow</title>
<style type="text/css">
#div1 { width: 700px; height: 150px }
#div2 { width: 600px; height: 100px; overflow: auto }
</style>
<script type="text/javascript">
function switchContent() {
var div1 = document.getElementById("div1").innerHTML;
var div2 = document.getElementById("div2").innerHTML;
document.getElementById("div1").innerHTML = div2;
document.getElementById("div2").innerHTML = div1;
}
</script>
</head>
<body>
<p>
<a href="javascript:switchContent();">Switch</a>
</p>
<div id="div1">
<p>p1</p>
</div>
<div id="div2">
<p>Smaller item.</p>
</div>
</body>
</html>
Related examples in the same category