jQuery 1.7

jQuery 1.7 has been released. Most important change indefinitely is the introduction of the new .on() and .off() methods.

If you’ve been using .bind() and .delegate(), transitioning to these new functions should be no problem. If you’ve been using .live(), which you shouldn’t (also see this test on jsperf), then it’s a great moment to transition to the new syntax.

// bind -> on
$('a').bind('click', myHandler);
$('a').on('click', myHandler);
 
// bind, with extra params -> on
$('form').bind('submit', { val: 42 }, fn);
$('form').on('submit', { val: 42 }, fn);
 
// unbind -> off
$(window).unbind('scroll.myPlugin');
$(window).off('scroll.myPlugin');
 
// delegate -> on
$('.comment').delegate('a.add', 'click', addNew);
$('.comment').on('click', 'a.add', addNew);
 
// undelegate -> off
$('.dialog').undelegate('a', 'click.myDlg');
$('.dialog').off('click.myDlg', 'a');

// live -> on
$('a').live('click', fn);
$(document).on('click', 'a', fn);

// die -> off
$('a').die('click');
$(document).off('click', 'a');

jQuery 1.7 Released →

Elsewhere , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>