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
// 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
$(document).off('click', 'a');

jQuery 1.7 Released →

About the author

Bramus is a Freelance Web Developer from Belgium. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.