Index Ai Academy
Glossary · Phase 8 · APIs

Event listener

Also written: event listeners

A function registered with addEventListener that runs each time something happens to an element, such as a click or a form submit.

Pages react through event listeners: element.addEventListener("click", handler) calls handler each time the element is clicked, with an event object describing what happened. For a chat box, listen for the form's submit event rather than the button's click: it fires for the button and for Enter in the text box.

Try it now

The question for each line: could this text have come from a model or a user?

Learn it properly

A chat front end in the browser · The DOM and events, model text kept out of innerHTML, a streamed reply parsed from server-sent events, and a Stop button. About 35 minutes.

Create a free account See what's in the lesson

Other terms from the same lesson

Never trained an AI?

Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.

Teach it to write