How to resovle the “ReferenceError: event is not defined” in javaScript events

This error is thrown when you try to access a variable that is undefined or is outside the current scope.

If you’re getting this error when using the event handling system, make sure you use the event object passed in as a parameter. Older browsers like IE offer a global variable event, and Chrome automatically attaches the event variable to the handler. Firefox will not automatically add it. Libraries like jQuery attempt to normalize this behavior. Nevertheless, it’s best practice to use the one passed into your event handler function.

Leave a comment

Your email address will not be published. Required fields are marked *