2

Looking for the best way to have two events for same button click (vanilla javascript only please), first one should happen on touchstart the other one on the TransitionEnd.

Is this would be correct / best way to do it?

document.getElementById("btn").addEventListener('touchstart', playSound, false {
        //Play sound, sync or async - not decided yet.
});

document.getElementById("btn").addEventListener('TransitionEnd', buttonAnimation, false {
        //do an action after css animation ends, like open dialog...
});
7
  • 3
    The "best" way would be to call document.getElementById("btn") once and assign the result to a variable. But other than that, yes, that's the correct way (assuming your actual code doesn't have syntax errors). Commented Sep 20, 2017 at 22:28
  • Possible duplicate of adding multiple event listeners to one element Commented Sep 20, 2017 at 22:28
  • What is that brace after false for? Commented Sep 20, 2017 at 22:36
  • Isn't the code to play the sound in the playSound function? Why do you have something that looks like a function body in the addEventListener call? Commented Sep 20, 2017 at 22:38
  • What is issue with current code? Commented Sep 20, 2017 at 22:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.