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...
});
Alex
  • 249
  • 1
  • 4
  • 17
  • 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). – Felix Kling Sep 20 '17 at 22:28
  • Possible duplicate of [adding multiple event listeners to one element](https://stackoverflow.com/questions/11845678/adding-multiple-event-listeners-to-one-element) – Luke Glazebrook Sep 20 '17 at 22:28
  • What is that brace after `false` for? – Barmar Sep 20 '17 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? – Barmar Sep 20 '17 at 22:38
  • What is issue with current code? – guest271314 Sep 20 '17 at 22:40
  • No issues at all, just wounder if it would be correct way to do it, maybe you can advice something better. Instead of playsound and buttonAnimation it is probably should be just function() if using my syntax? – Alex Sep 20 '17 at 22:45
  • Why do you have a sense that code is not correct? `touchstart` and `transitionend` event are not related. – guest271314 Sep 20 '17 at 22:54

0 Answers0