Hope this basic example helps:
HTML Code:
<script type="text/javascript">
function appendtoDiv(baseEl,targEl)
// Pass two params:
// 1 - The ID of the base element
// 2- The ID of target element
{
var p=document.createElement('p'); // Create a paragraph
// Create a text node to the created paragraph base on input's value
p.appendChild(document.createTextNode(document.getElementById(baseEl).value));
document.getElementById(targEl).appendChild(p); // Append the new paragraph to the target div
}
</script>
<input type="text" id="newinp"><input type="button" value="Add to Div" onclick="appendtoDiv('newinp','mydiv');">
<div id="mydiv" style="width:400px;padding:5px;border:1px solid #999;margin:10px;">
<h1>This is mydiv's content</h1>
<p>Another content</p>
</div>
Bookmarks