Skip to content

Instantly share code, notes, and snippets.

@codump
Last active November 21, 2022 18:20
Show Gist options
  • Save codump/a1748630880c7ea1dd5500312b2743a2 to your computer and use it in GitHub Desktop.
Save codump/a1748630880c7ea1dd5500312b2743a2 to your computer and use it in GitHub Desktop.
On click dynamically created elements.
$(document).on('click', '.addedElement', function(){
alert('Clicked on dynamic added element'); // Change to function you want.
});
@codump
Copy link
Author

codump commented Jun 27, 2022

When an element is dynamically created in the document/website the normal $('.addedElement').click(function(e){ click function doesn't work. The snippet above will solve that issue for u. When clicked on any element, dynamically added or not, with the class addedElement it will run the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment