0 works

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


dashboard+ Project

Posted 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
}
content_copyCopy to Clipboard

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


>> Browse more code snippets

more_vert