I have multiple jQuery click event handlers, each that run asynchronous code (i.e. AJAX call) when clicked.
I have some code like this:
$(selector1).click((e) => {
asyncCode1();
)};
$(selector2).click((e) => {
asyncCode2();
)};
$(selector3).click((e) => {
asyncCode3();
)};
$(selector1).click(); // runs asyncCode1()
$(selector2).click(); // runs asyncCode2()
$(selector3).click(); // runs asyncCode3()
I want $(selector2).click() to run only after $(selector1).click() has completed execution, since asyncCode1() generates elements in the DOM that will eventually be selected in $(selector2).
Should I be returning promises on each of the click handlers? I'm not sure about best practices and how to go about doing this.