2

I see in the documentation for .die() it says this:

In order for .die() to function correctly, the selector used with it must match exactly the selector initially used with .live().

Does the new method in jQuery 1.7 have this same limitation*?

*not actually sure if it's considered a limitation or a feature

ajbeaven
  • 8,509
  • 11
  • 74
  • 109

2 Answers2

4

The limitation is in fact still there.

Limitation with live demo

$(".bind").click(function(){
    $(".clone").live("click",function(){
        $(this).clone().insertAfter(this);
    });
});

$(".unbind").click(function(){
    $(".clone,.somethingelse").die("click");
});

working on demo

$(".bind").click(function(){
    $("body").on("click",".clone",function(){
        $(this).clone().insertAfter(this);
    });
});

$(".unbind").click(function(){
    $("body").off("click",".clone");
});

Limitation with on demo

$(".bind").click(function(){
    $("body").on("click",".clone",function(){
        $(this).clone().insertAfter(this);
    });
});

$(".unbind").click(function(){
    $("body").off("click",".clone,.somethingelse");
});

As you can see, you will need to specify the same selector as you did with live.

Joseph Marikle
  • 68,672
  • 14
  • 103
  • 120
0

Yes and no. Calling .off will need to mimic the syntax of .live, however, the selector argument is not required. Calling .off() for all click events on a particular element will unbind all click events, including ones that are delegated. If you only wanted to remove a particular delegated event, or only delegated events, you will still need to provide the selector for that delegated event or all other events will be removed too.

Kevin B
  • 92,700
  • 15
  • 158
  • 170