var buttons = document.getElementsByTagName('button'); var buttonsLength = buttons.length; for (var i = 0; i < buttonsLength; i++){ buttons[i].addEventListener('click', clickResponse, false); }; function clickResponse(){ // do something based on button selection here... alert(this.id); } Working JSFiddle here: http://jsfiddle.net/npvrx6sg/