Create a Title Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Title

Introduction

You can create a <title> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
</head>/*from  www  . j  a v  a2 s .c o  m*/
<body>

<button onclick="myFunction()">create a TITLE element</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 = "now created a TITLE element in the HEAD section of your document.";
}
</script>

</body>
</html>

Title Object Properties

Property Description
text Sets or gets the text of the document's title

Related Tutorials