How to Access Clicked Element From an Array With the Same Class


Saved by @bravocoder #javascript

var allActionButtons = document.getElementsByClassName("action-buttons");

for (var i = 0; i < allActionButtons.length; i++) {

  allActionButtons[i].addEventListener('click', functionToRunWhenClicked, false);


var functionToRunWhenClicked = function {
  // Add some stuff here

Must define functionToRunWhenClicked as a function in the same script. This is the same code used for the copy and bookmark buttons community page.