jQuery .die isnt killing an attached event?

Posted by adam on Stack Overflow See other posts from Stack Overflow or by adam
Published on 2010-04-03T12:56:57Z Indexed on 2010/04/03 13:03 UTC
Read the original article Hit count: 178

Filed under:

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;
    });

© Stack Overflow or respective owner

Related posts about jQuery