Skip to content

Instantly share code, notes, and snippets.

@nola
Last active December 30, 2015 19:49
Show Gist options
  • Select an option

  • Save nola/7876841 to your computer and use it in GitHub Desktop.

Select an option

Save nola/7876841 to your computer and use it in GitHub Desktop.
jquery .on with event. New and Old way with bind
$('body').on({
click: function() {
event.preventDefault();
console.log('item anchor clicked');
},
mouseenter: function() {
console.log('enter!');
}
});
// old way - .bind(events, handler);
$('body).bind('click', function(event) {
event.preventDefault();
console.log('item anchor clicked');
});
// new way (jQuery 1.7+) - on(events, handler);
$('body').on('click', function(event) {
event.preventDefault();
console.log('item anchor clicked');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment