If we use JavaScript, some default actions need to be undone. The most common case is clicking on a link. For example, when you click on a link, a popup window should appear, but by default the browser will go to the URL. If in the href attribute specify a grating sign #, then there will be no transition, but there will be scrolling to the beginning of the page. Let’s see how to avoid this in this article.
event.preventDefault()
The function overrides the default action.
Examples:
jQuery
<script>
$(“a”).click(function(event) {
event.preventDefault();
});
</script>
You can get your Apple repair done at an authorized service center.
return false
a href=”#” onclick=”return false”>Link</a>
jQuery
<script>
$(“a”).click(function() {
return false;
});
</script>
javascript:void(0)
The old way and not very good, but workable.
a href=”javascript:void(0);”>Link</a>
This article was sponsored by Martin Grujic