Reference to a div without IDs
<p>I have a problem with addEvent(or something else I don't know). This is my code.<br>
HTML :  </p>

<pre><code>&lt;div style="background-color:red;height:30px;width:30px;" &gt;&lt;/div&gt;
&lt;div style="background-color:yellow;height:30px;width:30px;" &gt;&lt;/div&gt;
</code></pre>

<p>JS :  </p>

<pre><code>function addEvent(elm,ev,fun)//Cross-browser addEvent
{
    if(elm.addEventListener)elm.addEventListener(ev,fun,false);
    else if(elm.attachEvent)
    {
        var r=elm.attachEvent("on"+ev,fun);
        return r;
    }
}

function myFun(x)
{
    alert(x.style.backgroundColor);
}

var allDiv=document.getElementsByTagName("div");
myFun(allDiv[0]);//Here it works
for(var i=0;i&lt;allDiv.length;i++) {
      //But not here when you click the div
      addEvent(allDiv[i],
               "click",function(){
                          myFun(allDiv[i])
                       });
}
</code></pre>

<p>I want that the alert works but without using IDs and without puting an inline onclick. Is it possible ?</p>

<p><a href="http://jsfiddle.net/G9gBS/1/" rel="nofollow">http://jsfiddle.net/G9gBS/1/</a></p>
