JSFiddle - React, Tailwind, and code Playground

by Oscar Jara

HTML

<a href="javascript:void(0);" id="l1">Link 1</a>
<a href="javascript:void(0);" id="l2">Link 2</a>
<a href="javascript:void(0);" id="l3">Link 3</a>
<a href="javascript:void(0);" id="l4">Link 4</a>
<div id="log"></div>

JavaScript

$('body').click(function(event) {
    
    var log = $('#log');
    
    if($(event.target).is('#l1')) {
       log.html(event.target.id + ' was clicked.');
    } else if ($(event.target).is('#l2')) {
       log.html(event.target.id + ' was clicked.');        
    } else if ($(event.target).is('#l3')) {
       log.html(event.target.id + ' was clicked.');
    } else if ($(event.target).is('#l4')) {
       log.html(event.target.id + ' was clicked.');
    } else {
       log.html('');    
    }
});