Javascript get “clicked” element addEventListener

You can use the event object and access its target property

document.getElementById("divId").addEventListener("click", someFunction);

function someFunction(event) {
  console.log(event.target.id);
}
<div id="divId">
  <span id="one">one</span>
  <span id="two"> two</span>
</div>

Leave a Comment