document.onclick = function (e) { e = e || window.event; elem = e.target || e.srcElement; switch (elem.id) { case 'bbutton_1': var a = 'a1'; break; case 'bbutton_2': var a = 'a2'; break; default: var a = 0; } }