Event listener

Updated: 04/26/2017 by Computer Hope

event listenerAn event listener is a procedure or function in a computer program that waits for an event to occur; that event may be a user clicking or moving the mouse, pressing a key on the keyboard, or an internal timer or interrupt. The listener is in effect a loop that is programmed to react to an input or signal.

Typically, the term event listener is 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