<!DOCTYPE html>
<html>
<body>

<p>Click the button to create a P element with some text.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var para = document.createElement("P");
    var t = document.createTextNode("This is a paragraph.");
    para.appendChild(t);
    document.body.appendChild(para);
}
</script>

</body>
</html>