Using the jq framework, how to make events execute during the capture phase.

for example, set one event in parent element An and another event in child element B.
when clicking on child elements, I want the event of A to trigger first (that is, to execute according to the capture phase)
but I have seen the source code, and the addEventlistener of the jq binding event can only be bubbled.
this puzzles me. Doesn"t jq give a solution?
this situation should have been encountered by someone. How is it solved?

$(box).on("click",function(e){console.log(0)}); //
$(b1).on("click",function(e){console.log(1)});
$(box).on("click.blur",".b1",function(e){console.log(2)});
Jun.09,2021

it turns out that I got it wrong. Thanks to Snake's reminder and checking the data, jquery itself does not provide an interface to trigger event handlers during the capture phase. The native addEventListener can be implemented, but it must be related to jq. The modification is as follows (using the html structure of A Snake)

  

it seems that jq itself has no intention of controlling the capture order for events.
then I try to assume that I want to add such a function to the jq framework and modify the original program.
first adds an optional parameter capture, to the binding event (event.add) to determine the capture order.
normally jq binds only one addEventListener to an element. However, in order to trigger the function according to the capture order and receive events with capture, you need to bind an additional addEventListener with capture as true.
adds the capture attribute to the jq event handling object (handlers).
then modify the event.handlers method to determine whether the capture or bubble trigger is triggered according to the event propagation phase (eventPhase). If it is a capture trigger, insert a handlers with a capture of true in the handler list (handlerQueue). The handler can then be executed in accordance with the normal process.
the above changes retain the ability to add capture triggers to the original construct, and you can also use jq.off (unbind events). I hope jq can add this function in the future.

Menu