f code example
Example: f
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>WEB222</title>
<style>
body { margin: 0 18%; }
#demo { background-color: lightblue; }
</style>
<script type="text/javascript">
function appendChildToNode(){
var newNode = document.createElement("p");
newNode.innerHTML = "This a new paragraph";
var demo_div = document.querySelector("#demo");
demo_div.appendChild(newNode);
}
function appendChildToPage(){
var newHeading = document.createElement("h2");
var t = document.createTextNode(" This is a heading ");
newHeading.appendChild(t);
document.body.appendChild(newHeading);
}
</script>
</head>
<body>
<h1>WEB222 - DOM node: Add node to node</h1>
<div id='demo'> This text is within the "demo" div element.</div>
<p> This paragraph is after the "demo" div element.</p>
<br>
<p><button onclick="appendChildToNode()">Append Child Node to Node</button></p>
<hr>
<p><button onclick="appendChildToPage()">Append Child Node to Web Page</button></p>
<hr><br>
<p><a href="" Download>Download</a></p>
</body>
</html>