0 points

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


dashboard

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_copy

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





LISTS WITH THIS SNIPPET

>> Browse more code snippets

more_vert