If you're starting out with javascript, now is the best time to learn not to touch unreliable properties; outerHTML is one of them; while supported by IE, Chrome and Opera, Firefox doesn't support it.
Taking the original code, this will work:
var content = document.getElementById("test").outerHTML;
var safe = content.replace(/</g,"<").replace(/>/g,">");
docuemnt.write(safe);
But, as much as using "outerHTML" is a bad idea, so is "document.write()". It is much better to have a div with an id on your page, and setting text there, rather than "wherever your code happens to be when document.write() gets called":
<html>
<head>...</head>
<body>
...
<div id="mylog"></div>
...
<body>
</html>
And then filling it with either:
// set the content for div 'mylog'
document.getElementById("mylog").innerHTML = content;
or by using something like jQuery, which gives you an API that hides all the crazy may-or-may-not-be-supported things, and guarantees that if you call it, it'll work:
// get html content
var content = $("#test").html();
// make it print safe
var safe = content.replace(/</g,"<").replace(/>/g,">");
// add it to the log as text
$("mylog").append(safe);
outerHTML
, the markup itself. – Myrna