There's some code, and it's not working. 

```
window.onload = function ()
{
    var div = document.getElementById ('main');
    var img = div.children;
    var i = 1;
    //console.log(img[i]);
    for (var i=1; i != img.length; i++)
    {
        img[i].onclick = function () 
        {
            console.log(img[i]);
        }
    }
}

```

Please, explain me Why is img[i] in `console.log(img[i]);` undefined ?
How this bug can be fixed?