Source Code: (back to article)
<a href="https://www.example.com" id="myLink">Go to Example.com</a>

<script>
document.getElementById('myLink').addEventListener('click', function(event) {
event.preventDefault(); // Stops the default link behavior
alert('Default action prevented! Link will not open.');
});
</script>