jQuery preventDefault() method

What is jQuery preventDefault() method?

The event.preventDefault() method is used to prevent the default action of the element. For example, in HTML forms, as Submit button is clicked, preventing it from submitting the data to the server.

Similarly, it can be used to prevent other elements default action like opening links etc..

Example of event.preventDefault() to prevent form submit

In this example, as you try to submit the form by pressing the “submit now” button without entering any text in the First name field, the form default behavior of submission is prevented:

jQuery preventDefault

Experience this example online

Was this article helpful?

Related Articles

Leave A Comment?