jQuery event.preventDefault()Method
Example
Prevent the link from opening the URL:
$("a").click(function(event){
event.preventDefault();
});
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. |
Other Extensions
jQuery Event Methods