Algo así te decía:
Código PHP:
<html>
<head>
<style>
*{ cursor: default; }
div{
background-color: #eee;
margin-top: 2px;
text-align: center;
font-size: 20px;
}
div:hover{ background-color: #ccc; }
</style>
</head>
<body>
</style>
<div id="foo">foo</div>
<div id="bar">bar</div>
<div id="baz">baz</div>
<div id="candy">candy</div>
<div id="fruits">fruits</div>
<div id="vegetable">vegetable</div>
<script type="text/javascript">
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp */)
{
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in t)
fun.call(thisp, t[i], i, t);
}
};
}
function addEvent(obj,fun,type){
if(obj.addEventListener){
obj.addEventListener(type,fun,false);
}else if(obj.attachEvent){
var f=function(){
fun.call(obj,window.event);
}
obj.attachEvent('on'+type,f);
obj[fun.toString()+type]=f;
}else{
obj['on'+type]=fun;
}
}
var divs = ['foo', 'bar', 'baz', 'candy', 'fruits', 'vegetable'];
divs.forEach(function(div,i,o){addEvent(document.getElementById(div),function(e){alert(this.id);},'click');});
</script>
</body>
</html>