Event listener

Updated: 11/13/2018 by Computer Hope
event listener

An event listener is a procedure or function in a computer program that waits for an event to occur. Examples of an event are the user clicking or moving the mouse, pressing a key on the keyboard, disk I/O, network activity, or an internal timer or interrupt. The listener is programmed to react to an input or signal by calling the event's handler.

The term event listener is often specific to Java and JavaScript. In other languages, a subroutine that performs a similar function is referred to as an event handler.

The following JavaScript code would add an event listener to an HTML document:

document.addEventListener('click', myfunction, false);

In this example, when the HTML is rendered in a browser, the listener calls the function "myfunction" (which must be defined elsewhere in the script) any time the user clicks the mouse button.

Event, Input, Programming terms, Signal, Subroutine