Get Title Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Title

Introduction

The Title object represents an HTML <title> element.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM objects</title>
</head>/*from w w w  .  j av a 2 s . co  m*/
<body>

<button onclick="myFunction()">get the text of the document's title</button>

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

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

</body>
</html>

Related Tutorials