1

According to the jQuery API Description: live is completely removed in latest version. But its been used in our projects extensively. For example:

$('div.collapsed').live('mouseover', function () {
        TBD.GENERAL.showLoginOther(this);

});

$(".info_bar .filter a, .pagination a").live("click", function () {
    TBD.DHTML.shadeWithLoading($(this).data('container-id'));
    $.getScript(this.href);
    return false;
});

$("form[loading-effect]").live('ajax:before', function () {
    $(this).find('.button_panels, .loading_panels').toggle();
});

.........

etc.

Now if I want to use the latest jquery what will be the correct replacement of live? delegate or on ?

Anticipating a bit explanation. Thanks in advance

Muntasim
  • 6,689
  • 3
  • 46
  • 69

1 Answers1

1

Since .live() is deprecated you better to use .on() like

$('div.collapsed').on('mouseover', function () {

or can use like

$(document).on('mouseover','div.collapsed', function () {

Because

  1. You can’t use .live() for reusable widgets.
  2. stopPropagation() doesn't work with live.
  3. live() is slower.
  4. live() is not chainable.

and the .on() method provides all functionality required for attaching event handlers.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • 1
    why not `delegate` ? or why `on`. Explanation will be appreciated – Muntasim Jun 19 '13 at 13:17
  • 1
    None of them are equivalent to live(). Live attaches event handlers to document level: `$(document).on('mouseover','div.collapsed', function () {...})` – A. Wolff Jun 19 '13 at 13:22
  • both are same as you said i think – GautamD31 Jun 19 '13 at 13:22
  • Your edit is better now ;) +1 but you should remove $('div.collapsed').on('mouseover', function () {...}) which bring confusion as it's not delegating event, here, its equivalent to .bind() – A. Wolff Jun 19 '13 at 13:23