Friday, March 27, 2009

What does calling preventDefault() on an event do How is this enforced

Question :What does calling preventDefault() on an event do? How is this enforced?
Answer :Cancels an event's default behavior if that behavior can be canceled.. For example, the
doubleClick event has an associated default behavior that highlights the word under the mouse
pointer at the time of the event. Your event listener can cancel this behavior by calling the
preventDefault() method.
You can use the Event.cancelable property to check whether you can prevent the default behavior
associated with a particular event. If the value of Event.cancelable is true, then preventDefault() can
be used to cancel the event; otherwise, preventDefault() has no effect.

No comments: