Assuming FORM contains INPUT, there are the following listeners:
Javascript
function formFirst(e) { ... } function formLast(e) { ... } function inputFirst(e) { ... } function inputLast(e) { ... } function middle(e) { ... } document.getElementById('form').addEventListener('change',formFirst,true); document.getElementById('form').addEventListener('change',formLast,false); document.getElementById('input').addEventListener('change',inputFirst,true); document.getElementById('input').addEventListener('change',inputLast,false);
desired shooting order
formFirst() // normal - outer element, useCapture = true inputFirst() // normal - triggering element, declared first middle() // -- how to do this? inputLast() // normal - triggering element, declared second formLast() // normal - outer element, useCapture = false
nature of the problem and attempts to solve
Native code at the FORM level, formFirst , formLast and middle , but does not have access to the INPUT, inputFirst and inputLast - although it can add its own listeners to INPUT.
Attempt 1 to modify formFirst() to create and send a new change Event (will be ignored in formFirst ), which will call inputFirst() but have no way to stop the distribution to prevent inputLast() being called later.
Attempt 2 to add middle added as a listener in INPUT, but cannot guarantee the order of operation of two listeners of the same type and the same useCapture.
The premise of attempt 2 is incorrect β the order of fire is determined by the order of the announcement in the target element.
Here are the rules
Element useCapture=false triggers with useCapture=false , starting at the outer element and working on the target element
a) if more than one useCapture=true triggered for the same element, then the declaration order.
in the target element, the declaration order, regardless of useCapture
Element out-of- useCapture=false triggers with useCapture=false , starting from the innermost element and working from the target element
a) if more than one useCapture=false starts the same element, then the declaration order.
cc young
source share