dynamic onClick not working
<p>I know im doing something really really stupid here.Im getting the error document.getElementById() is null or not an object. Could some one please help me with this?</p>

<pre><code>&lt;body&gt;
&lt;div id="box1" style="width:100px;height:100px;background:#ccc;"&gt;&lt;/div&gt;
&lt;div id="box2" style="width:100px;height:100px;background:#ccc;"&gt;&lt;/div&gt;
&lt;div id="box3" style="width:100px;height:100px;background:#ccc;"&gt;&lt;/div&gt;
&lt;div id="box4" style="width:100px;height:100px;background:#ccc;"&gt;&lt;/div&gt;
&lt;div id="box5" style="width:100px;height:100px;background:#ccc;"&gt;&lt;/div&gt;
&lt;script&gt;

for (var i = 0; i &lt; 5; i++) {
document.getElementById('box' + i).onclick = function() {alert('You clicked on box #' + i);};
}

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

<p>Thank You</p>
