Using hammer.js on dynamically loaded content

↘锁芯ラ 提交于 2019-12-10 14:46:29

问题


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?


回答1:


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);
});


来源:https://stackoverflow.com/questions/13267364/using-hammer-js-on-dynamically-loaded-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!