'Event capturing not functioning as expected

I'm trying things with events capturing in JavaScript and it's not working as expected.

For example, here is some html :

<div id="test">
    <a href="someimage.jpg"><img src="someimage.jpg" /></a>
</div>

and JavaScript :

document.getElementById("test").addEventListener("click", function(event) {
    event.preventDefault();
    console.log(event.target.nodeName);
}, true);

My understanding is that since capturing is set to true, clicking the image should log DIV to the console. Instead, it logs IMG...

If someone could explain why, or point to a doc that explains it, it would be great.



Solution 1:[1]

My understanding is that since capturing is set to true, clicking the image should log DIV to the console. Instead, it logs IMG...

That's simply wrong. event.target will always return the element the event was triggered on, independently of the event handling phase. See the spec.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Felix Kling