I am trying to use JavaScript to get a clicked element\'s information.
Here is the jsFiddle.
And below is my code.
Welcome to StackOverflow!
e.target
should give you the exact element that was clicked to generate the event.
e.currentTarget
will give you the element
that the event is at when the function
was called (after bubbling up from the e.target
)
div.addEventListener('click', (e) => {
console.log(e.target) // the p that was clicked
console.log(e.currentTarget) // this div
})