Skip to content

Instantly share code, notes, and snippets.

@chrisyeung1121
Created June 16, 2015 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisyeung1121/9f54ee0925a556d969d5 to your computer and use it in GitHub Desktop.
Save chrisyeung1121/9f54ee0925a556d969d5 to your computer and use it in GitHub Desktop.
binding will work with AJAX created DOM
// Will not work after new DOM created on AJAX
$('.photo-options-hero').on('click', function() {
$(this).closest('.gallery-item').addClass('hero').siblings().removeClass('hero');
});
// Will work after AJAX DOM Creation
$('body').on('click', '.photo-options-hero', function() {
$(this).closest('.gallery-item').addClass('hero').siblings().removeClass('hero');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment