<button type="button" class="btn">1</button>
<button type="button" class="btn">2</button>
<button type="button" class="btn">3</button>
<button type="button" class="btn">4</button>
<button type="button" class="btn">5</button>
const buttons = document.querySelectorAll('.btn');

buttons.forEach(function(button) {
  button.addEventListener('click', function() {
    console.log(this); // 你所點擊的 DOM
  });
});
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.