jQuery event.preventDefault()Method

jQuery 事件方法jQuery Event Methods

Example

Prevent the link from opening the URL:

$("a").click(function(event){
    event.preventDefault();
});

Try it Yourself »

Definition and Usage

The event.preventDefault() method prevents elements from performing their default behavior.

For example:

  • Prevent form submission when the submit button is clicked
  • Prevent the link of the following URL from opening

Tip:Please use theevent.isDefaultPrevented()method to check whether preventDefault() was called on the specified event.


Syntax

event.preventDefault()

Parameter Description
event Required.eventThe parameter comes from the event binding function.


jQuery 事件方法jQuery Event Methods

Other Extensions