Javatpoint Logo
Javatpoint Logo

jQuery event.preventDefault() method

As the name implies, the preventDefault() method prevents the occurrence of default action of the selected element. As an example, this method can stop a submit button from submitting a form, or it can prevent an anchor from following a URL. This method does not return a value.

Syntax

The preventDefault() method does not accept any parameters. The event mentioned in the above syntax is mandatory to be specified.

Let's understand the method by using some illustrations.

Example1

It is a simple example of using the preventDefault() method. In this example, we are using the event.preventDefault() method for preventing an anchor to follow the URL. When we try to click the given URL, the link will not work

Test it Now

Output

After the execution of the above code, the output will be -

jQuery event.preventDefault() method

Example2

It is another simple example of using the event.preventDefault() method. In this example, we are using the method to prevent the submit button from submitting an HTML form. Here, there is an HTML form including some textfields and buttons. There is a submit button that submits the data of the form. But when we try to click the submit button, the button will not work.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery event.preventDefault() method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA