Javascript DOM HTML Title text Property set

Introduction

Change the text of the document's title:

document.getElementsByTagName("TITLE")[0].text = "A new title text..";

Click the button to change the text of the document's title.

View in separate window

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Objects</title>
</head>/*from w  ww .j  av a2 s .  c  o m*/
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementsByTagName("TITLE")[0].text = "A new title text..";
  document.getElementById("demo").innerHTML = "The text of the document's title was changed.";
}
</script>

</body>
</html>



PreviousNext

Related