Is it possible to emulate event capturing in Internet Explorer?
An example:
<a>one</a> <a>two</a> <a>three3</a> <script> var links = document.getElementsByTagName("A"); for (var i=0; i < links.length; i++) { links[i].onclick = function(){ alert("clicked"); }; } </script>
I want to prevent all these click events from firing. I can do that with a single event observer:
document.addEventListener("click", function(e) { e.stopPropagation(); e.preventDefault(); }, true);
How can I do the same in IE? IE < 9 does not support addEventListener
. It does support attachEvent
, but it doesn't have useCapture
option.
I've found setCapture method, but it doesn't look related to the W3 capturing model.
With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. With capturing, the event is first captured by the outermost element and propagated to the inner elements.
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. It is the opposite of event bubbling, where events propagate outwards from the target to the outer elements. Capturing happens before bubbling.
Generally you can't because of the event order. In IE the events will start bubbling from the target element without the capturing phase so you can't catch them beforehand.
There's only one thing you can do, and it's only possible if you manage all the event handlers.
addEvent
with capture parameterIf capturing is required do the following
Array
Array
invoking the original event handler on each of the elements If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With