Add Event Listener to Multiple Buttons with the Same Class

PHOTO EMBED

Thu Jan 26 2023 06:02:46 GMT+0000 (Coordinated Universal Time)

Saved by @dqmeek #js #html

<button class="save">Save 1</button>
<button class="save">Save 2</button>
<button class="save">Save 3</button>

<script>
  let saveBtn = document.getElementsByClassName('save');
  Array.from(save).forEach(function (el) { 
    el.addEventListener('click', handler) 
  });
  function handler() {
    console.log('Clicked');
  }
</script>
content_copyCOPY

https://www.thiscodeworks.com/add-event-listener-to-multiple-buttons-with-the-same-class-javascript/5efa75c76c23bc0014be6336