I want to unbind the anchor after the first click, but when user click a specific button, I want to rebind the click event to this anchor
I wrote this code
$(document).ready(function(){
$("a.package").click(function(){
//alert('click');
$(this).unbind('click');
// the rest of the code
});
$('#activate').click(function(){
$('a.package').bind('click');
// the rest of the code
});
});
the unbind function works well, but the bind function does not work, why? and how to make it work?
You have to pass a callback to bind, it doesn't remember anything once it is unbound. Meaning when you specified the bind again in the #activate.click you would have to specify the function there. Probably the best way to do this is specifiy the function else where and use that for the bind call. In the example below i use jquerys .data to store a function under 'clickFunc' and then use this as the callback for the .click . You could just also use a var.
http://jsfiddle.net/nj65w/13/
Store your click function in a variable so that it can easily be re-assigned...
Try changing the first binding to .one().