javascript write a line of html code with a button
<p>hey guys i have got this far with a chat system but now i am stuck at this point.</p>

<p>the js script will look for a element called chat and if it is not found it will put it in with all of the other elements stated here </p>

<pre><code>&lt;div class='chat' id='chat'&gt;&lt;div class='ch' id='ch'&gt;&lt;h2&gt;Chat&lt;/h2&gt;&lt;/div&gt;&lt;div class='chatbox'&gt;&lt;div class='messages'&gt;&lt;/div&gt;&lt;textarea id='message' class='chatinp' rows='3' cols='27'&gt;&lt;/textarea&gt;&lt;button class='send'&gt;Send&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;
</code></pre>

<p>My problem is how to insert that whole line of code with javascript into the html document.
how would you do this?</p>

<p>My javascript script is you need to see</p>

<pre><code>&lt;script type="text/javascript"&gt;
var num = new Number();
num = 0

function chat(){


if(!document.getElementById("chat")){
       document.write("&lt;div class='chat' id='chat'&gt;&lt;div class='ch' id='ch'&gt;&lt;h2&gt;Chat&lt;/h2&gt;&lt;/div&gt;&lt;div class='chatbox'&gt;&lt;div class='messages'&gt;&lt;/div&gt;&lt;textarea id='message' class='chatinp' rows='3' cols='27'&gt;&lt;/textarea&gt;&lt;button class='send'&gt;Send&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;")   
} 
else 
{
var obj = document.getElementById("chat").cloneNode(true);
var p = $(".chat");
var offset = p.offset();
num = num + 1;        

if (num &lt;15) {
obj.id = obj.id + num;
document.getElementById("ch").id = obj.id;
document.body.appendChild(obj);
document.getElementById("chat").style.left = "700px";
}
}




}
&lt;/script&gt;
</code></pre>
