JSFiddle - React, Tailwind, and code Playground
HTML
<section>section
<div>div<p>span</p></div>
</section>
CSS
body > * {
padding: 50px;
}
section {
background-color: blue;
}
div {
background-color: yellow;
}
p {
background-color: red;
width: 100px;
height: 100px;
}
JavaScript
var section = document.querySelector('section');
section.onclick = handler(section);
function handler(elComAuscultador) {
return function(e) {
var target = e.target.tagName.toLowerCase();
var self = this.tagName.toLowerCase();
var log = [
'Clicaste no elemento ' + target,
'O this é o elemento ' + self,
'this == elComAuscultador é verdadeiro? ' + (this == elComAuscultador ? 'sim' : 'não')
];
alert(log.join('\n'));
}
}