Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript native equivalent for jQuery event.preventDefault [duplicate]

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?

like image 559
Mahdi Avatar asked Oct 06 '12 08:10

Mahdi


People also ask

What can I use instead of event preventDefault?

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.

What is preventDefault method in Javascript?

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.

What's the difference between event preventDefault () and event stopPropagation () methods in Javascript?

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.

What is the opposite of preventDefault in Javascript?

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.


2 Answers

preventDefault is a DOM method. See the W3C specification here.

like image 114
PHeiberg Avatar answered Oct 14 '22 05:10

PHeiberg


jQuery wrap around native JavaScript event object. preventDefault is JavaScript method. you can achieve preventDefault in jQuery by return false;.

like image 21
Anoop Avatar answered Oct 14 '22 05:10

Anoop