JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<body>
<div id="parent">
click on this link -> <a href="www.google.com" id="anchor">google</a>
</div>
<pre id="results"></pre>
</body>
</html>
JavaScript
$(document).ready(function () {
var results = $("#results");
$("#parent").delegate("a", "click", function (event) {
event.preventDefault();
results.append("\nparent delegate handler\n");
results.append(" this id = " + $(this).attr("id") + "\n");
results.append(" target id = " + $(event.target).attr("id") + "\n");
results.append(" target == this = " + (event.target == this) + "\n");
results.append(" $(this) == target = " + ($(this) == event.target) + "\n");
results.append(" this == $(target) = " + (this == $(event.target)) + "\n");
results.append(" $(this) == $(target) = " + ($(this) == $(event.target)) + "\n");
});
$("#parent a").click(function (event) {
event.preventDefault();
results.append("\nanchor handler\n");
results.append(" this id = " + $(this).attr("id") + "\n");
results.append(" target id = " + $(event.target).attr("id") + "\n");
results.append(" target == this = " + (event.target == this) + "\n");
results.append(" $(this) == target = " + ($(this) == event.target) + "\n");
results.append(" this == $(target) = " + (this == $(event.target)) + "\n");
results.append(" $(this) == $(target) = " + ($(this) == $(event.target)) + "\n");
});
$("#parent").click(function (event) {
event.preventDefault();
results.append("\nparent handler\n");
results.append(" this id = " + $(this).attr("id") + "\n");
results.append(" target id = " + $(event.target).attr("id") + "\n");
results.append(" target == this = " + (event.target == this) + "\n");
results.append(" $(this) == target = " + ($(this) == event.target) + "\n");
results.append(" this == $(target) = " + (this == $(event.target)) + "\n");
results.append(" $(this) == $(target) = " + ($(this) == $(event.target)) + "\n");
});
});