Skip to content

Instantly share code, notes, and snippets.

@byeblogs
Last active August 29, 2015 14:18
Show Gist options
  • Save byeblogs/0c4b6d0b4c4050bef1e5 to your computer and use it in GitHub Desktop.
Save byeblogs/0c4b6d0b4c4050bef1e5 to your computer and use it in GitHub Desktop.
Delegate / On Function
// Without Event Delegation
$('button').click(function() {
console.log('click this button')
});
$('body').click(function() {
$(this).append('<button>hello im new button</button>')
$('button').click(function(event) {
console.log('click this button')
});
});
// With Event Delegation
$('body').on('click', 'button', function() {
console.log('click this button')
});
$('body').click(function() {
$(this).append('<button>hello im new button</button>')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment