You can use document.getElementById('id').innerHTML to access the contents of an element.
Unfortunately the browsers (particularly IE) will fiddle with your code behind the scenes, so innerHTML is not an exact replica of what you put in.
However, this is a quick example of how to achieve close to what you want...
Code:
<div id="example1">
<strong>This is an example</strong>
</div>
<pre id="example1_code"></pre>
<button onclick="showHtml('example1')">Show HTML</button>
<script type="text/javascript">
function escape(text)
{
var result = text.replace(/</g,'<');
result = result.replace(/>/g,'>');
result = result.replace(/"/g,'"');
return result;
}
function showHtml(id)
{
var code = document.getElementById(id).innerHTML;
document.getElementById(id+'_code').innerHTML = escape(code);
}
</script>
You can use the already mentioned style.display to handle if you only want to show one or other at a time.