Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hammer.js on dynamically loaded content

I'm playing around with hammer.js for a web app.

I can get it to work just fine, except on content loaded with ajax.

I use the hammer.js special-events plugin for jquery.

The following works fine:

$('#menu a').on("tap", function(event) {
 //console.log(event);
});

But when I use the jquery delegation syntax:

$('body').on("tap", '#menu a', function(event) {
 //console.log(event);
});

Nothing happens...

What is the right syntax?

like image 991
afcdesign Avatar asked Oct 06 '22 02:10

afcdesign


1 Answers

Try this if you dynamically add the a element :

$('#menu').on("tap", 'a', function(event) {
  //console.log(event);
});

or this:

$('#menu').hammer().on("tap", 'a', function(event) {
  //console.log(event);
});
like image 129
Akkumulator Avatar answered Oct 10 '22 05:10

Akkumulator