Javascript TypeError: result of expression is not an object
<p>This should be real simple... But it ain't... >.&lt;</p>

<pre><code>var x = document.getElementById('x');
function snooze()
{
x.style.height = '10px';
}
</code></pre>

<p>Upon execution, the error I get is:</p>

<p><code>TypeError: Result of expression 'x' [null] is not an object.</code></p>

<p>Edit: Heads up, it works when I put the var declaration inside the function. I don't understand... :-(</p>

<pre><code>function snooze()
{
var x = document.getElementById('x');
x.style.height = '10px';
}
</code></pre>
