event.preventDefault();

The event.preventDefault() method stops the default action of an element from happening.

by Zuhaib Siddiqui

HTML

<p>The event.preventDefault() method stops the default action of an element from happening.</p>

<h1>For example:</h1>
<ul>
    <li>Prevent a submit button from submitting a form</li>
    <li>Prevent a link from following the URL</li>
</ul>


<a id="clickHere" href="http://jquery.com" target="_blank">default click action is prevented</a>
<div id="log"></div>

JavaScript

$( "#clickHere" ).click(function( event ) {
event.preventDefault();
$( "#log" ).append( "default " + event.type + " prevented<br>" )
.appendTo( "#log" );
});