Javascript DOM HTML Title text Property get

Introduction

Return the text of the document's title:

var x = document.getElementsByTagName("TITLE")[0].text;

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

View in separate window

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Objects</title>
</head>//ww w. j a  va 2  s .com
<body>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementsByTagName("TITLE")[0].text;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The text property sets or gets the text of the document's title.

The text property accepts and returns a String type value.




PreviousNext

Related