<div id="div1">
    <span>span1</span>
</div>
div1.addEventListener('click', (e) => {
  const tempButton = e.target // by user
  if (tempButton.tagName.toLowerCase() === "button") {
    console.log('button被点击了')
    console.log('button内容是' + tempButton.textContent)
    console.log('button id是' + tempButton.dataset.id)
  }
});

for (let i = 0; i < 10; i += 1) {
  setTimeout(() => {
    const button = document.createElement('button')
    button.textContent = 'click ' + i
    button.setAttribute("data-id", i)
    div1.appendChild(button)
  }, i * 1000)
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.