Get the title of the current document:
The text inside the HTML title element is the title of the page.
var x = document.title;
Click the button to display the title of the document.
<!DOCTYPE html> <html> <head> <title>My title</title> </head>/*from w w w. j a v a 2 s . c o m*/ <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.title; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The title property sets or gets the title of the current document.