Skip to content

Instantly share code, notes, and snippets.

@nickserv
Created June 25, 2013 14:19
Show Gist options
  • Save nickserv/5858810 to your computer and use it in GitHub Desktop.
Save nickserv/5858810 to your computer and use it in GitHub Desktop.
jQuery event binding with on/off
// see http://blog.jquery.com/2011/11/03/jquery-1-7-released/
$('a').bind('click', myHandler);
$('a').on('click', myHandler);
$('form').bind('submit', { val: 42 }, fn);
$('form').on('submit', { val: 42 }, fn);
$(window).unbind('scroll.myPlugin');
$(window).off('scroll.myPlugin');
$('.comment').delegate('a.add', 'click', addNew);
$('.comment').on('click', 'a.add', addNew);
$('.dialog').undelegate('a', 'click.myDlg');
$('.dialog').off('click.myDlg', 'a');
$('a').live('click', fn);
$(document).on('click', 'a', fn);
$('a').die('click');
$(document).off('click', 'a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment