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:
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:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("a").click(function(event){ event.preventDefault();/* w w w . j a v a2 s . c o m*/ }); }); </script> </head> <body> <a href="http://java2s.com/">Go to site</a> </body> </html>