CancelImage Upload

How to access a websites title definition via JavaScript

Accessing the HTML title object via JavaScript and DOM is not really a task of great difficulty. All that is needed is the correct path. Since this path consists of two words it would really take a grand master in failure to get this wrong;-):

var docTitle = document.title;

As you can see document.title is the key in the above code. Below then we will go a step further, and actually load the title into a span tag inside the HTML document:

<title>Accessing a HTML document's title property with JavaScript</title>
<script language="JavaScript">

function getTitle()

        var spanTitle = document.getElementById("title");

        spanTitle.innerHTML = document.title;



<body onload="javascript:getTitle();">

<b>Page Title: </b>
<span id="title"></span>


Piece of cake!

Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •