Sireini
Sireini

Reputation: 4262

Create multiple eventListeners to one specific element

I want to create an click and a touch start event here is my code:

 google.maps.event.addDomListener(div, "click",function(event: any) {
        google.maps.event.trigger(self.overlayView, "click");
        event.stopPropagation();
    });

How do I create an simple implementation for this without doing this:

 google.maps.event.addDomListener(div, "touchstart",function(event: any) {
        google.maps.event.trigger(self.overlayView, "click");
        event.stopPropagation();
    });

Upvotes: 0

Views: 23

Answers (1)

Rajesh
Rajesh

Reputation: 24915

You can export function to a named function and bind same function to both event.

Sample Fiddle

document.getElementsByClassName('tile')[0].addEventListener('click', handler)
document.getElementsByClassName('tile')[0].addEventListener('mousedown', handler)

function handler(e) {
  console.log(e)
}

Upvotes: 1

Related Questions