jQuery preventDefault: Main Tips
- The
event.preventDefault
method prevents the event's default action from being executed. - The event.isDefaultPrevented is used to check whether the event handler triggered the jQuery preventDefault method.
event.preventDefault Explained
The jQuery event.preventDefault
method disturbs the actions of events and prevents them from being completed. For instance, the example below shows that the event preventDefault will not allow an URL to be opened after it is clicked:
Invoking the jQuery preventDefault will cancel the event. Therefore, the default action of the event will not take place, just like the URL is not opened in the code example. Remember that the method does not take any arguments: it is simply written as event.preventDefault()
.