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

Javascript examples for jQuery Method and Property:event.isDefaultPrevented

Description

The event.isDefaultPrevented() method checks whether the preventDefault() method was called.

Syntax

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials