Advertisement
728x90
Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.
For example, if you wanted to detect field changes inside a specific form, you can use event delegation technique,
javascript
1var form = document.querySelector("#registration-form");
2
3 // Listen for changes to fields inside the form
4
5form.addEventListener(
6 "input",
7 function (event) {
8 // Log the field that was changed
9 console.log(event.target);
10 },
11 false
12);Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 26
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
110of476