Create a <p> element with some text, use innerText to set the text, and append it to the document:
Click the button to create a P element with some text.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w w w .j a v a2 s . co m*/ var para = document.createElement("P"); para.innerText = "This is a paragraph."; document.body.appendChild(para); } </script> </body> </html>