Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
Event capturing is one of two ways to do event propagation in the HTML DOM. In event capturing, an event propagates from the outermost element to the target element.
Event capturing is a type of event propagation where the event is first captured by the outermost element, and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the innermost target DOM element.
You need to pass true value for addEventListener method to trigger event handlers in event capturing phase.
const parent = document.querySelector(“div”);
const child = document.querySelector(“.child”);
parent.addEventListener(“click”,
function () {
console.log(“Parent”);
},
true
);
child.addEventListener(“click”, function () {
console.log(“Child”);
});
// Parent
// Child