JSFiddle - React, Tailwind, and code Playground

by Hans Dijkema

HTML

<p>Contents of P: Click here!</p>
<p><a href="http://www.google.be">Click here for a link!</a></p>
<p><a href="http://www.google.nl"><b>Click here for a link i.e. a parent element!</b></a></p>

JavaScript

window.onclick = function(e) {
  var node = e.target;
  while (node != undefined && node.localName != 'a') {
    node = node.parentNode;
  }
  if (node != undefined) {
    alert('Link!: ' + node.href);
    /* Your link handler here */
    return false;  // stop handling the click
  } else {
    alert('This is not a link: ' + e.target.innerHTML)
    return true;  // handle other clicks
  }
}