Trying to get the width of an h1 tag with Javascript
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;

&lt;script type = "text/javascript"&gt;

var textHeadingArray = ["Bloom Defender", "Civilization Wars", "Flight", "Rebuild 2",  "Wonderputt"];

var textHeadingIndex = 0;

function changeMainImage() {

textHeadingIndex++;
        if (textHeadingIndex &gt;= textHeadingArray.length) {
        textHeadingIndex = 0;   
}

var changeTheHeading = document.getElementById("slidehsowheading").innerHTML = textHeadingArray[textHeadingIndex];

var heading = document.getElementById("slidehsowheading").style.width;

var sizeOfHeading = heading;
alert(sizeOfHeading);

var subtraction = 75 - sizeOfHeading;

var changeTheHeadingAgain = document.getElementById("slidehsowheading").style.left = subtractionRounded + "px";
}

var mainTiming = setInterval("changeMainImage()", 5000);

&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;h1 id = "slidehsowheading"&gt;Bloom Defender&lt;/h1&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Im trying to use this code to change the heading for a slideshow, I am kinda new to javascript so my problem is that when the alert pops up it returns as null(the alert was just for debugging), so when i try to use the null width from the h1 in this equation it is wrong. The equation is supposed to get the width of the heading after it has been changed by the timer and divid by 2 and subtract that from the width of its background divided by 2 which is 75, with this formula you can center the heading in its background element</p>
