We can create a <title> element via the document.createElement()
method:
var x = document.createElement("TITLE");
Click the button to create a TITLE element.
<!DOCTYPE html> <html> <head> </head>/*w w w . ja va 2 s .c om*/ <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.createElement("TITLE"); var t = document.createTextNode("HTML DOM Objects"); x.appendChild(t); document.head.appendChild(x); document.getElementById("demo").innerHTML = "You have now created a TITLE element in the HEAD section of your document."; } </script> </body> </html>