Skip to content

Instantly share code, notes, and snippets.

@ajmeese7
Created February 3, 2020 20:10
Show Gist options
  • Save ajmeese7/914497df9074fcfac820d0f784bfde88 to your computer and use it in GitHub Desktop.
Save ajmeese7/914497df9074fcfac820d0f784bfde88 to your computer and use it in GitHub Desktop.
Add listeners to dynamically added elements with jQuery
// Allows listener to apply to dynamically added elements
$("body").unbind().click(function() {
if (event) {
var target = event.target;
if (target.className === 'exampleClass' ||
target.parentElement.className === 'exampleClass')
{
doSomethingToElement();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment