B
B
Barrakuda742016-11-05 11:20:22
JavaScript
Barrakuda74, 2016-11-05 11:20:22

Why is addDomListener needed in Google Maps API?

Hello dear experts! Everything is clear with addListener in Google Maps, it has its own events. But addDomListener serves to handle browser events. The question is simple, why is it needed in the presence of addEventListener , and the presence of jQuery - .on ?
Two very simple examples:

google.maps.event.addDomListener(document.querySelector('a'), 'click', function(e) {
    map.setZoom(13);
});

$('a').on('click', function(e) {
    map.setZoom(13);
});


It’s just that with such an abundance of methods for binding handlers, sometimes you get confused about what to choose ((The manual says that the method is cross-browser, but I don’t understand what this cross-browser is expressed in. addEventListener and .on isn’t it cross -browser?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2016-11-05
@Barrakuda74

1) addEventListener doesn't work in old IE. Or do you think that Google maps were written only yesterday? Even at the end of 2016, some projects need to support older browsers.
2) Why do you think that everyone should use jQuery in their projects? If you don't have a link to something, use whatever method works best for your project. If you use jQuery everywhere, hang events via .on(), if you have IE from 9 and don't have jQuery, then see for yourself.
Google's task is to make their maps work everywhere, without any dependencies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question