问题
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