document.title

In this chapter you will learn:

  1. How to get and set document title in Javascript
  2. How to change the document title

Document titme

document.title returns the document title, changes the document title.

<!DOCTYPE HTML> <!--   ja v a 2 s .co  m-->
<html> 
    <body> 
        <script> 
            document.writeln("<pre>"); 
            document.writeln("compatMode: " + document.compatMode); 
            document.writeln("dir: " + document.dir); 
            document.writeln("domain: " + document.domain); 
            document.writeln("referrer: " + document.referrer); 
            document.writeln("title: " + document.title); 
            document.write("</pre>"); 
        </script> 
    </body> 
</html>

Click to view the demo

Change the document title

The following code changes the document title.

<!DOCTYPE HTML> <!--from  j  a  v  a  2 s. c om-->
<html> 
    <body> 
        <script> 
            document.writeln("<pre>"); 
            document.writeln("compatMode: " + document.compatMode); 
            document.writeln("dir: " + document.dir); 
            document.writeln("domain: " + document.domain); 
            document.writeln("referrer: " + document.referrer); 
            document.writeln("title: " + document.title); 
            document.write("</pre>"); 
            
            document.title = "new title";
            
        </script> 
    </body> 
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. How to get the URL for current document in Javascript
Home » Javascript Tutorial » Document
Document Object
document.body
document.characterSet
document.charset
document.compatMode
document.cookie
document.defaultCharset
document.defaultView
getElementsByTagName(tagName)
document.getElementsByClassName
document.getElementsByName
document.images
document.lastModified
document.location
document.implementation
document.querySelectorAll
document.readyState
document.title
document.URL
document.writeln