Javascript DOM HTML Title Object get

Introduction

The Title object represents an HTML <title> element.

We can access a <title> element by using getElementsByTagName():

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

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>//  w w  w . j a v a2  s.  c  o  m
<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>



PreviousNext

Related