This is the code:
<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">
<p onclick="myFunction(event)">Click on a paragraph. An alert box will alert the element that triggered the event.</p>
<p><strong>Note:</strong> The target property returns the element that triggered the event, and not necessarily the eventlistener's element.</p>
<script>
function myFunction(event) {
alert(event.target.nodeName);
}
</script>
</body>
</html>
So when I click on <p>
, there are two pop-up windows which are all regarding to P, but shouldn't we have one P and one Body as onclick event is associated with <body>
tag?