Getting a DHTML node as an html string

I've created a 'div' using DHTML. Is it possible to see what it looks like as a string of HTML. So something like this:

var d=document.createElement('DIV');
d.style.border='1px solid';
d.innerHTML='Hi there';

Converted into:

'<DIV STYLE="border:1px solid">Hi there</DIV>'
zumpoofAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jplevyakCommented:
There is an outerHTML property that would return the full HTML as a string but this is only supported in IE. However, there was already a post on this site with this issue where some experts have provided workarounds.

How to get outerHTML in IE and Mozilla (Netscape)
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21221807.html
0
Michel PlungjanIT ExpertCommented:
Since I cannot add to that question, here is a combination of yours and theirs with your dynamic generation used for the hidden div:


<body>
<div id="theDiv" style="border:solid 1px red;width:300">
<p>abc</p>
<p>def </p>
</div>

<form id="abc" name="myForm" action="xyx.com" target="_blank">
  <p><input type="text" name="t2"> <input> <input type="submit"> </p>
</form>

<script>
var d=document.createElement('DIV');
d.id="x";
d.style.border='1px solid';
d.innerHTML='Hi there';
document.body.appendChild(d)
</script>


<script>
function getOuterHTML(obj){
 
 var temp=document.getElementById(obj).cloneNode(true)
 var d=document.createElement('DIV');
 d.style.display='none';
 d.appendChild(temp)
 var outer=d.innerHTML
 d.innerHTML=""
 return outer
}
alert(getOuterHTML("theDiv"))
alert(getOuterHTML("abc"))
alert(getOuterHTML("x"))
</script>

</body>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.