Post

On click dynamically created elements

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

1
2
3
$(document).on('click', '.addedElement', function(){
	alert('Clicked on dynamic added element'); // Change to function you want.
});
This post is licensed under CC BY 4.0 by the author.