Skip to main content

The new .on() and .off() APIs unify all the ways of attaching events to a document in jQuery — and they're shorter to type! All the existing event binding methods (and their corresponding unbinding methods) are still there in 1.7, but we recommend that you use .on() for any new jQuery project where you know version 1.7 or higher is in use. Here are some examples of mapping between the old and new API calls:

$('a').bind('click', myHandler); // old way
$('a').on('click', myHandler); // v1.7+ way

$('form').bind('submit', { val: 42 }, fn); // old way
$('form').on('submit', { val: 42 }, fn); // v1.7+ way

$(window).unbind('scroll.myPlugin'); // old way
$(window).off('scroll.myPlugin'); // v1.7+ way

$('.comment').delegate('a.add', 'click', addNew); // old way
$('.comment').on('click', 'a.add', addNew); // v1.7+ way

$('.dialog').undelegate('a', 'click.myDlg'); // old way
$('.dialog').off('click.myDlg', 'a'); // v1.7+ way

$('a').live('click', fn); // old way
$(document).on('click', 'a', fn); // v1.7+ way

$('a').die('click'); // old way
$(document).off('click', 'a'); // v1.7+ way