var idList = ['id1', 'id2', 'id3']; for (var i = 0; i < idList; i++) { node = document.getElementById(idList[i]); node.onclick = fn, node.onmouseover = fn, node.onmouseout = fn; }