How to rewrite the code using jQuery
<p>How to rewrite the code using jQuery?</p>

<pre><code> &lt;script type="text/javascript"&gt;
    window.onload = function(){
        var array = document.getElementsByTagName('div');
        for (var i=0; i&lt;array.length; i++) {
            (function(i) {
                array[i].onclick = function() {
                    alert(i);
                }
            })(i);
        }
    };
    &lt;/script&gt;
    &lt;div&gt;0&lt;/div&gt;
    &lt;div&gt;1&lt;/div&gt;
</code></pre>

<p>Thanks...</p>
