Create all necessary element using javascript in the body and insert , the resul
ID: 3542899 • Letter: C
Question
Create all necessary element using javascript in the body and insert , the result should equavilent of the html page below,..This will be the javascript file will be inserted into the body of HTML.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of the document</title>
</head>
<body>
<h2>Heading</h2>
<hr>
<p>Start with empty HTML body</p>
<hr>
<p> Build the body one node at the time using javascript</p>
<p>by building a DOM tree in memory</p>
</body>
</html>
Explanation / Answer
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function myFunction()
{
var h=document.createElement("H2");
var t=document.createTextNode("Heading");
h.appendChild(t);
document.body.appendChild(h);
var hr1=document.createElement("hr");
document.body.appendChild(hr1);
var p1=document.createElement("p");
var p2=document.createTextNode("Start with empty HTML body");
p1.appendChild(p2);
document.body.appendChild(p1);
var hr2=document.createElement("hr");
document.body.appendChild(hr2);
var p3=document.createElement("p");
var p4=document.createTextNode("Build the body one node at the time using javascript");
p3.appendChild(p4);
document.body.appendChild(p3);
var p5=document.createElement("p");
var p6=document.createTextNode("by building a DOM tree in memory");
p5.appendChild(p6);
document.body.appendChild(p5);
};
</script>
</head>
<body>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.