<html>
<head>
<title>add element to another element using javascript</title>
</head>
<body style="background:lightgray">
<p>Click the button to test:</p>
<button onclick="test()">add p element into a div element</button>
</br>
<textarea id="edit" style="height:200px;width:240px">
<p>hello world<span>!</span></p>
</textarea>
<script>
function test() {
var el = document.createElement( 'body' );
var edit= document.getElementById("edit");
var div= document.createElement( 'div' );
div.innerHTML =edit.value;
addElement(el,div);
edit.value=el.innerHTML;
}
function addElement(father,child) {
father.appendChild(child);
}
</script>
</body>
</html>
Comments
Post a Comment