Skip to main content
3 of 3
code refomate, beautified given link
honk
  • 9.9k
  • 11
  • 83
  • 90
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.

shmuli
  • 5.2k
  • 6
  • 36
  • 65