Event listener
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)callshandlereach time the element is clicked, with an event object describing what happened. For a chat box, listen for the form'ssubmitevent 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.
Other terms from the same lesson
- DOM: The tree of objects a browser builds from a page's HTML; JavaScript changes the page by changing it.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.