Performance difference between jQuery’s .live(‘click’, fn) and .click(fn)

If not, why would you ever use click
or bind(‘click’)?

Because $.live() has some significant disadvantages

  • Live events do not bubble in the traditional manner and cannot be
    stopped using stopPropagation
    (This changed in jquery 1.4.4) or
    stopImmediatePropagation. For example,
    take the case of two click events –
    one bound to “li” and another “li a”.
    Should a click occur on the inner
    anchor BOTH events will be triggered.
    This is because when a
    $(“li”).bind(“click”, fn); is bound
    you’re actually saying “Whenever a
    click event occurs on an LI element –
    or inside an LI element – trigger this
    click event.” To stop further
    processing for a live event, fn must
    return false.
  • Live events currently only work when used against a selector. For
    example, this would work: $(“li
    a”).live(…) but this would not:
    $(“a”, someElement).live(…) and
    neither would this:
    $(“a”).parent().live(…).

Leave a Comment