I can't find any solution to get this jquery events to work.
$(window).one('click',function(){
console.log('hide something');
return false;
});
$('a.ajax').live('click', function(e){
console.log('ajax requesting');
return false;
});
I want that "A" element should do ajax request instead of its default as well as firing the window's click event once. Removing the "return false" from A's click will trigger window's click but will not prevent its default behavior after the first click and continue with non-ajax request.
Both handlers are in different closure so I can't a create a variable to help it work, and I also don't want to create a global variable.
From my example above should result:
-> ajax requesting (1st click)
-> hide something (1st click)
-> ajax requesting (2nd click)
-> ajax requesting (3rd click)
Thanks for helping!
In your a
event handler add as the first line e.preventDefault()
(and remove the return false).
$('a.ajax').live('click', function(e) {
e.preventDefault();
console.log('ajax requesting');
});
'return false' will cancel all future events (even the propagated one up to window), but preventDefault() will just prevent the regular action from happening but continue the event chain.
More information: jQuery e.preventDefault documentation