The purpose of document.body.onclick = e => console.log(e.target); is to catch all clicks. Unfortunately, the click on the first link won't be displayed in the console. Is there a way to grab links from the page, even those that have stopPropagation()?
https://jsfiddle.net/htLw9cxy/
function myFuncCanNotBeEdited(e) {
e.stopPropagation();
//...
//and do some other important code here
}
document.body.onclick = e => console.log(e.target);
<body>
<div style="border: 1px solid red; padding: 10px;">
<a href="#" onclick="myFuncCanNotBeEdited(event);">Edit</a>
<a href="#">Remove</a>
</div>
</body>
Ok, this is really hacky, so be careful as it involve modifying built in prototype.
You can intercept globally the
stopPropagationprototype.Below I've knocked up a very simple Snippet, you could extend to do more checks, making sure it's a link etc.