Computer >> Computer tutorials >  >> Programming >> Javascript

How to display the title of a document with JavaScript?


To get the title of a document, use the title property in JavaScript. You can try to run the following code to show the title of a document with JavaScript.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   <body>
      <script>
         var str = document.title;
         document.write("Title: "+str);
      </script>
   </body>
</html>