event.preventDefault() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:event.preventDefault


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

You can use event.isDefaultPrevented() method to check if the preventDefault() method was called for the event.

For example you can use event.isDefaultPrevented() method to:

  • Prevent a submit button from submitting a form
  • Prevent a link from following the URL


Parameter Require Description
event Required. The event parameter comes from the event binding function

The following code shows how to Prevent a link from opening the URL:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        event.preventDefault();//from   w ww.j  a  v  a 2  s.c o m

<a href="http://book2s.com/">Go to site</a>


Related Tutorials