<html>
<body>
<p>Click the button to create a SECTION element containing a H1 and P element.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.createElement("SECTION");
x.setAttribute("id", "mySection");
document.body.appendChild(x);
var heading = document.createElement("H1");
var txt1 = document.createTextNode("Section Heading");
heading.appendChild(txt1);
document.getElementById("mySection").appendChild(heading);
var para = document.createElement("P");
var txt2 = document.createTextNode("Some text in section..");
para.appendChild(txt2);
document.getElementById("mySection").appendChild(para);
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_section_create by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:08:08 GMT -->
</html>