From cb88857b52df6357edaf4e768e06075d3e597deb Mon Sep 17 00:00:00 2001
From: Aurelio De Rosa The In all browsers, the The The handler list for an element is set when the event is first delivered. This means that even if you try to remove an event handler inside another one for the same event executed first, the removed handler will be executed anyway. It will not be executed the following times because it's correctly removed. This behavior goes against the W3C events specification. It's worth noting that this is an edge case and this behavior allows to keep the logic simple. To better understand this case, consider the following code: In the code above, The In all browsers, the The The handler list for an element is set when the event is first delivered. This means that even if you try to remove an event handler inside another one for the same event executed first, the removed handler will be executed anyway. It will not be executed the following times because it's correctly removed. This behavior goes against the W3C events specification. It's worth noting that this is an edge case and this behavior allows to keep the logic simple. To better understand this case, consider the following code: The handler list for an element is set when the event is first delivered. Adding or removing event handlers on the current element won't take effect until the next time the event is handled. To prevent any further event handlers from executing on an element within an event handler, call focus
and blur
events are specified by the W3C to not bubble, but jQuery defines cross-browser focusin
and focusout
events that do bubble. When focus
and blur
are used to attach delegated event handlers, jQuery maps the names and delivers them as focusin
and focusout
respectively. For consistency and clarity, use the bubbling event type names.load
, scroll
, and error
events (e.g., on an <img>
element) do not bubble. In Internet Explorer 8 and lower, the paste
and reset
events do not bubble. Such events are not supported for use with delegation, but they can be used when the event handler is directly attached to the element generating the event.error
event on the window
object uses nonstandard arguments and return value conventions, so it is not supported by jQuery. Instead, assign a handler function directly to the window.onerror
property.
+ var $test = $( "#test" );
+
+function handler1() {
+ console.log( "handler1" );
+ $test.off( "click", handler2 );
+}
+
+function handler2() {
+ console.log( "handler2" );
+}
+
+$test.on( "click", handler1 );
+$test.on( "click", handler2 );
handler2
will be executed anyway the first time even if it's removed using .off()
. However, the handler will not be executed the following times the click
event is triggered.focus
and blur
events are specified by the W3C to not bubble, but jQuery defines cross-browser focusin
and focusout
events that do bubble. When focus
and blur
are used to attach delegated event handlers, jQuery maps the names and delivers them as focusin
and focusout
respectively. For consistency and clarity, use the bubbling event type names.load
, scroll
, and error
events (e.g., on an <img>
element) do not bubble. In Internet Explorer 8 and lower, the paste
and reset
events do not bubble. Such events are not supported for use with delegation, but they can be used when the event handler is directly attached to the element generating the event.error
event on the window
object uses nonstandard arguments and return value conventions, so it is not supported by jQuery. Instead, assign a handler function directly to the window.onerror
property.event.stopImmediatePropagation()
. This behavior goes against the W3C events specification. To better understand this case, consider the following code:var $test = $( "#test" );
function handler1() {