Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an event was prevented

In JavaScript, how can I check if an event (like keypress) was prevented with e.preventDefault()? I'm not using jQuery.

like image 729
ethanzheng Avatar asked Jun 11 '13 02:06

ethanzheng


People also ask

What does event stopPropagation () do?

Event.stopPropagation() The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases. It does not, however, prevent any default behaviors from occurring; for instance, clicks on links are still processed.

What does e preventDefault () do?

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. Clicking on a link, prevent the link from following the URL.

How do I stop event preventDefault?

preventDefault() Method: It is a method present in the event interface. This method prevents the browser from executing the default behavior of the selected element. This method can cancel the event only if the event is cancelable.

What is event preventDefault () in angular?

Event.preventDefault() The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.


1 Answers

You can check the event object's defaultPrevented property (which is a boolean indicating if preventDefault was ever called for that particular event object).

like image 58
bfavaretto Avatar answered Oct 03 '22 08:10

bfavaretto