Switch html with assigning the innerHTML : innerHTML « Node Operation « JavaScript DHTML

Switch html with assigning the innerHTML


<style type="text/css">
#div1 { width: 700px; height: 150px }
#div2 { width: 600px; height: 100px; overflow: auto }

<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;
<a href="javascript:switchContent();">Switch</a> 
<div id="div1">
<div id="div2">
    <p>Smaller item.</p>


Related examples in the same category

1.'innerHTML' Example
2.Get the paragraph tag and set its innerHTML value
3.Modifying Elements after Page loads