Skip to main content
code refomate, beautified given link
Source 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: http://jsfiddle.net/npvrx6sg/here.

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/

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.

 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/

 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/

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/

Source Link
shmuli
  • 5.2k
  • 6
  • 36
  • 65

 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/