Possible Duplicate:
event.preventDefault() vs. return false
I'm not sure, but as far as I see, event.preventDefault
is coming from jQuery
. if yes, I'm wondering is there any native equivalent in Javascript doing the same?
The following example demonstrates how invalid text input can be stopped from reaching the input field with preventDefault() . Nowadays, you should usually use native HTML form validation instead.
The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur. For example, this can be useful when: Clicking on a "Submit" button, prevent it from submitting a form.
preventDefault() prevents the browsers default behaviour, but does not stop the event from bubbling up the DOM. The event. stopPropagation() prevents the event from bubbling up the DOM, but does not stop the browsers default behaviour.
As you probably might have already worked out based on the simple explanation above: the opposite of event. preventDefault() is nothing. You just don't prevent the event, by default the browser will allow the event if you are not preventing it.
preventDefault
is a DOM method. See the W3C specification here.
jQuery wrap around native JavaScript event object.
preventDefault
is JavaScript method. you can achieve preventDefault
in jQuery by return false;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With