FrontendDeveloper.in

JavaScript question detail

What is an event delegation

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,

var form = document.querySelector("#registration-form");

// Listen for changes to fields inside the form
form.addEventListener(
"input",
function (event) {
// Log the field that was changed
console.log(event.target);
},
false
);
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399