Javascript examples for jQuery Method and Property:event.isDefaultPrevented
The event.isDefaultPrevented() method checks whether the preventDefault() method was called.
Parameter | 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, and check if preventDefault() was called:
<!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();/*from ww w . ja va2s . c o m*/ console.log("Was preventDefault() called: " + event.isDefaultPrevented()); }); }); </script> </head> <body> <a href="http://java2s.com/">Go to site</a> </body> </html>