Quantcast
Channel: adding multiple event listeners to one element - Stack Overflow
Viewing all articles
Browse latest Browse all 19

adding multiple event listeners to one element

$
0
0

So my dilemma is that I don't want to write the same code twice. Once for the click event and another for the touchstart event.

Here is the original code:

document.getElementById('first').addEventListener('touchstart', function(event) {    do_something();    });document.getElementById('first').addEventListener('click', function(event) {    do_something();     });

How can I compact this? There HAS to be a simpler way!


Viewing all articles
Browse latest Browse all 19

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>