I am using jquery as so
$('.mybutton').live('click', function(){
// do something
});
this is called when the document is ready but when the document is ready there are ‘mybutton’ classes being used, but if the user clicks somewhere a new form appears which uses the button with the class ‘mybutton’. But this does not seem to be working, and it doesn’t have the required handler.
Is this because there where no ‘mybutton’ classes to start with on the document ready?
If
live()ever doesn’t seem to work for an element that has the proper selector, like.mybuttonin your case, it is likely because some ancestor element of the.mybuttonis preventing bubbling from happening.If any ancestor of a
.mybuttonhas:or:
This will effectively disable
.live()for that.mybuttonbecause.live()needs the event to bubble all the way up to the root.