AvailabilityMethods
In JavaScript, however, you define an event handler simply by writing a function that accepts an Event object as its argument. The name of the function does not matter, and the function itself is used in place of an EventListener object. See the Section section. DescriptionThis interface defines the structure of an event listener or event handler. In languages such as Java, an event listener is an object that defines a method named handleEvent( ) that takes an Event object as its sole argument. In JavaScript, however, any function that expects a single Event argument, or a function that expects no argument, can serve as an event listener. Example// This function is an event listener for a "submit" event function submitHandler(e) { // Call a form-validation function defined elsewhere if (!validate(e.target)) e.preventDefault( ); // If validation fails, don't submit form } // We might register the event listener above like this document.forms[0].addEventListener("submit", submitHandler, false); See AlsoEvent, EventTarget; Chapter 19 Passed toEventTarget.addEventListener( ), EventTarget.removeEventListener( ) |