Search code examples
javascriptdom-eventsevent-bubbling

Why is the event listener for the invalid event not being called when using event bubbling?


When I try add an event listener to the invalid event of the document it is not called when I use the default event bubbling like this.

document.addEventListener("invalid", function (e) {
    console.log(e.target);
}, false);

When I set the last parameter to true the event listener is called like expected. Thanks to What is event bubbling and capturing? I think I understand the difference between event capturing and bubbling, but I don't understand how this applies to my case. Why is it making a difference here?


Solution

  • According to the MDN reference, which is usually accurate and which appears to match reality in this case, invalid events do not bubble. They fire only on the input and the form.