Created
February 3, 2020 20:10
-
-
Save ajmeese7/914497df9074fcfac820d0f784bfde88 to your computer and use it in GitHub Desktop.
Add listeners to dynamically added elements with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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