benmajor / jQuery-Touch-Events

A collection of mobile event plugins for jQuery.
MIT License
699 stars 225 forks source link

Problem to attach events #135

Closed antoniogarcez closed 7 years ago

antoniogarcez commented 7 years ago

Hi,

I'm trying to attach an event to an image: $(SlideshowElem).on('swipeend', 'img', function (event, swipe) { });

But this does not work and I tried in this way: $('img', SlideshowElem).on('swipeend', function (event, swipe) { });

And worked. So, I want to know why the first piece of code does not work.

P.S. One question, can I use event.stopPropagation();?

benmajor commented 7 years ago

There is a known issue with event delegation and these events. I suspect it's related to the combination of start and end events and this is on the roadmap to be fixed. For now, I'm afraid you need to use the alternate delegation.

Regarding your postscript, not natively, no. You will need to stopPropagation for each individual event inside of the swipe event (i.e. touchstart, mousedown, etc.)