I have a function assigned to a click event on a calendar – I need the click event in live() because the standard .click() does not bind itself to the newly displayed days when you switch months in the calendar – which triggers some AJAX based on the calendar date selected.
I need to prevent the user from firing any more AJAX until the previous request has completed so achieved this by immediately unbinding the click listener with .die('click'). However, I am unable to bring the eventWrap click listener back to life again with $('.eventWrap').live('click') from within itself it would appear.
Is there a solution to my problem?
$('.eventWrap').live('click', function() {
$('.eventWrap').die('click');
do ajax stuff
//bring the .eventWrap click listener back to life
//$(.eventWrap).live('click'); does not work as I had hoped
}
You could simply add a class within the click, and only do ajax if the class doesn’t exist
Use
on()instead oflive()if using jQuery 1.7