When working with JavaScript, how do you go about restoring the default behavior of a DOM element's event handler?
For instance, let's say you've set the onkeypress
event for an input element:
elem.onkeypress = function() { alert("Key pressed!"); }
But later on, you want to remove this event. Is it acceptable to simply set the onkeypress
property to null? I've tried this method and it seems to work, but I'm not sure if it's the recommended approach.