0

I try to click "RecalcButton" after "AutoFitButton". AutoFitButton has own click event. I have added new event with the code below, but my event runs first. How can i make it run last?

AutoFitButton = document.getElementsByClassName("someclass")[11];
RecalcButton = document.getElementsByClassName("someclass")[9];

function recalcAfterClick() {
    RecalcButton.click();
    }

AutoFitButton.addEventListener("click", recalcAfterClick, false);
TimeTq
  • 111
  • 1
  • 1
  • 3
  • Can you please provide a background on why are you trying do this way? There might be better option if you specify your requirements! – Always Helping Aug 25 '20 at 09:20
  • Can you provide a snippet to demonstrate? Click edit then `[<>]`, see [mcve]. According to this answer https://stackoverflow.com/a/14071760/2181514 it should run last – freedomn-m Aug 25 '20 at 09:29
  • I have to agree with comment above - there's probably a better way to do this, but hard to explain in a comment. Essentially, instead of calling button.click, you call the function that the button was going to click - eg `function recalcAfterClick() { recalc() }` and (as you've tagged jquery and it's so much more succinct) `$("#recalcButton").click(() => { recalc(); })` - ie they both call a 3rd function, so no need to call .click, then your auto button becomes `$("#autoFitButton").click() => { autoFit(); recalc(); });` – freedomn-m Aug 25 '20 at 09:36
  • @freedomn-m If I got you right, you are talking about creating a button and binding several functions to it at once.Unfortunately, I have already created buttons. I can just add some function to them. – TimeTq Aug 25 '20 at 10:30
  • I'm talking about your buttons calling common/shared *functions* that multiple buttons can also call. Rather than a button trying to "click" a 2nd button. – freedomn-m Aug 25 '20 at 10:37

0 Answers0