Example

Prevent a link from opening the URL:

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

Try it yourself »

Definition and Usage

The preventDefault() method stops the default action of an element from happening (for example, preventing a form being submitted when a submit button is clicked).

Syntax

event.preventDefault()

Parameter Description
event Required. Specifies the event to prevent the default action for. The event parameter comes from the event binding function