January 2017
Intermediate to advanced
496 pages
10h 7m
English
In JavaScript development, we often think of our application as reacting to user events on the page. For instance, we may listen for a submit button on the page to be clicked, and when it is, validate a form. Functions that respond to these user events are sometimes dubbed event handlers or event listeners.
In a simple JavaScript application, we register these event handlers by querying the DOM for some element and adding an event listener function to run when the event of interest occurs. Here is how we might do this:
document.querySelector('form').addEventListener('click', validateForm);
function validateForm() {
alert('The form is valid!');
}
In the early days of JavaScript, we probably would have used HTML event attributes in ...
Read now
Unlock full access