How to know the id of current Html element when clicking on a Html element using plain JavaScript?
<div id="myId">
<div>
<h2>First Div</h2>
</div>
<div>
<h2>Second Div</h2>
</div>
</div>
I would like to catch "myId" while I am clicking on the body of this div. That means I would like to get the ID of parent div when I click on First Div and Second Div.
My JS code is like below.
document.onclick = function(e) {
alert(e.target.id)
}