Please enable Javascript for better experience...
jQuery event.preventDefault() and event.isDefaultPrevented() Method
By Rahul Kumar Jha | Aug 18, 2015 | In Tips | Total Views [ 2775 ]
Taged In
(0 Like)

JQuery methods event.preventDefault() and event.isDefaultPrevented() can be used to prevent default action of that element.


If you are using a tag and your client say that it should not perform navigation or if you are using a button and you think, it should not perform click event, then JQeury has a solution for you. Simply use event.preventDefault() to prevent default action behavior and event.isDefaultPrevented() to check if your changes are applied or not.


Below is the use of preventDefault() method. I am applying it on a tag and it will not let it navigate to desired url.



Below is the use of isDefaultPrevented() method. It will check if changes applied or not.

    alert("Is preventDefault() applied: " + event.isDefaultPrevented());


Here is the sample code.

<!DOCTYPE html>
<script src=""></script>
<a href="">Dot Net Concept</a>
<p>The preventDefault() method will prevent the link to navigate to the URL and isDefaultPrevented() method tells that change has been applied successfully.</p>

Hope it helps you.

Share this

About the Author

Rahul Kumar Jha
Rahul Kumar Jha
Founder, Developer

Public profile: user/profile/99900001

Has working experience in different phases of Software Development Life Cycle (SDLC) in CMS, Gaming, Health Care and Financial Services domain using Agile pattern. Working experience in Design patterns, ASP.NET, MVC, ANGULAR, ANGULAR JS, Windows application, WCF, ADO.NET, SQL Server and Test Driven Development (TDD) environment with JQuery, JavaScript, N-Unit, Entity Frameworks, LINQ, Code Refactoring and Business Objects Models.

User's Comments

Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID