How to use preventDefault() Method in jQuery

This article describe about jQuery Event preventDefault() Method.
  • 2550

jQuery Event preventDefault() Method

For prevent of the default action of an element from happening (for example, preventing from submitted when a submit button is clicked) use the preventDefault() method.

Syntax

event.preventDefault()

 

Parameter Description
Event Required. It define the event to use. The event parameter comes from event bind method

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("a").click(function (event) {

            event.preventDefault();

        });

    });

</script>

</head>

<body>

<a href="/">Go to dotnetheaven.com </a>

<p>The preventDefault() method will prevent the link above from the URL.</p>

</body>

</html>

 

Output

 

preventDefault method pic20.jpg


Note: In the output URL mention, but prevent from from click.

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.