What is event.preventDefault() in jQuery?

<form id="f"><button type="submit">Send</button></form>
$('#f').on('submit', function (e) {
  e.preventDefault();
  console.log('default prevented: ' + e.isDefaultPrevented());
});
$('#f').trigger('submit');
Console output

default prevented: true

  • preventDefault() stops the browser action.
  • stopPropagation() stops the event going to the parents.
  • return false in a jQuery handler does both.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.