Say I have some code like this which is called on $(document).ready()
$(".someClass").click(function(){
//do something
});
Later on I have some jquery to create an element with the class someClass. Is there anyway to automatically attach the click from above or do I have to manually attach it again?
There is
live, which also listens for new elementsBut, as of jquery 1.7 it has been deprecated. It’s advised to use
oninstead.But in order to use
on, you need a container for the elements you want to bind a handler. Of course you could usebodyordocumentbut it’s better to use a more specific element