I am stuck trying to unbind and rebind a click event. I want to "save" the click event, unbind it, and rebind it with a conditional statement.
I'm able to get the click handler saved using the information here: jQuery find events handlers registered with an object
I am on an older version of jQuery (1.5), so I'm using the data("events") method.
So far...
var events = $('#myElement').data("events");
alert(events.click[0].handler);
$('#myElement').unbind('click');
Now it will alert me the handler function and it looks correct. I want to add stuff to it, but I thought for starters I would just try rebinding the same click event. However, I'm not sure how to rebind correctly. Things I have tried:
$('#myElement').bind('click', null, events.click[0].handler); // gives 'click.0 is null or not an object
$('#myElement').bind('click', events.click[0].handler); // gives 'click.0 is null or not an object
$('#myElement').bind('click', null, events.click); // seems to have no effect
$('#myElement').bind('click', events.click); // seems to have no effect
So I feel I almost have it but I'm not sure what to do from here. How do I use the events variable to rebind the click event?
Thank you for any and all help.