Getting a DHTML node as an html string

Posted on 2006-03-26
Last Modified: 2006-11-18
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');'1px solid';
d.innerHTML='Hi there';

Converted into:

'<DIV STYLE="border:1px solid">Hi there</DIV>'
Question by:zumpoof
    LVL 3

    Expert Comment

    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)
    LVL 75

    Accepted Solution

    Since I cannot add to that question, here is a combination of yours and theirs with your dynamic generation used for the hidden div:

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

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

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

    function getOuterHTML(obj){
     var temp=document.getElementById(obj).cloneNode(true)
     var d=document.createElement('DIV');'none';
     var outer=d.innerHTML
     return outer


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now