event.preventDefault() vs return false in JavaScript event handlers
Hello everyone! I started learning JavaScript and jQuery, and I encountered a confusing situation. When I want to cancel the default browser action (for example, following a link or submitting a form), I see two ways: I can call `event.preventDefault()`, or I can simply write `return false` at the end of the handler.
For example, I have this form:
```html
```
I write a handler:
```javascript
document.getElementById('myForm').addEventListener('submit', function(event) {
// data validation...
event.preventDefault();
});
```
But in jQuery I often see this code:
```javascript
$('#myForm').on('submit', function() {
// data validation...
return false;
});
```
It see
No answers yet.
Log in to leave an answer