I have two functions hooked on the submit event of a form. Each function is in a different place, and one function can affect the other.
How can I force one of these functions to be hooked with the lowest priority (ie. be the last to be executed)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are four ways I can think of:
Manage the callbacks yourself, and only have one event handler that calls the functions in the desired order.
In the function that is supposed to fired last, do the actual work in a zero-millisecond timeout. If all other functions work synchronously (and you can live with the final one not happening during the event bubbling), this will achieve the same thing.
Bind the to-be-fired-last handler higher up in the DOM tree. You’ll have to test if that works with
submitevents; bubbling of these events doesn’t work in IE, but the jQuery docs mention that this has been normalized in jQuery. May be worth a try.Somewhat similar to 1., when binding any other handler than the low-priority one, unbind the latter, bind the new one, and finally re-bind the last-to-be-run.