jQuery .die isnt killing an attached event?
- by adam
Hi I've just started experimenting with .live and .die and having some great results but one thing isn't working.
I've been tinkering with firebugs console to try out my written code live to see if i can figure out the reason why .die isn't killing off an attached event.
First if i do this
//attach ajax submission
$('a[href$=edit]').live("click", function(event) {
$.get($(this).attr("href"), null, null);
return false;
});
Then as expected when I click on a link the ajax fires off and my server side code injects a form for inline editing.
But sometimes I want to disable this behaviour and also make the link unclickable so I do the following
//unbind ajax form creation when we click on a link, then disable its semantic behaviour
$('a[href$=edit]').die("click").click( function(){ return false; } );
which works but if then try to remove this and restore that ajax goodness with the code below it doesn't work, Instead the link remains unclickable. I cant figure out why? Can anyone help?
//remove any previous events from the links
$('a[href$=edit]').die();
//attach ajax submission
$('a[href$=edit]').live("click", function(event) {
$.get($(this).attr("href"), null, null);
return false;
});