You need to add a click
handler and, if your func
was called, prevent the default action of the click. Here I'm using timer
as a flag:
var timer = 0;
var func = function () {
$("body").append("1");
timer = 0;
};
$(document).on('mousedown' , 'a' , function(e){
timer = setTimeout(func, 1000);
}).on('mouseup mouseleave' , 'a' , function(e){
if (timer) {
clearTimeout(timer);
}
}).on('click', 'a', function() {
if (!timer) {
return false;
}
});