If you don't want to have the default beahavior (such as following a link), you can prevent it with the event.preventDefault() function.
It still allow the event propagation but disable the default action.
DOM Event Handler - On Properties with Javascript (Interface Definition Language - IDL )
<p>Clicking on the below link will not work</p>
<a href="https://gerardnico.com">Go to the best website on the planet</a>
document.querySelector('a').onclick = function(event) {
console.log( "You are no longer following the link" );
event.preventDefault();
}
What are the HTML On Attributes ? (known also as event handler content attributes)
function prevent(event){
event.preventDefault();
}
<p>Clicking on the below link will not work</p>
<a href="https://datacadamia.com" onClick="prevent(event)">Go to the best website on the planet</a>
If the expression returns false, the event will be consumed, preventing the browser from performing any default action.
<p>Clicking on the below link will not work</p>
<a href="https://datacadamia.com" onClick="return false;">Go to the best website on the planet</a>