a = new object();
a.loadInterface();
$("button").click(function() {
a.doSomething();
});
The problem is that a.loadInterface() is what loads the button into the DOM, and it happens at the end of a $.post() because data from the server is needed to populate some attributes of the button.
So what I think is going on is, JavaScript reads the button.click detector but at that time there is no button for it to bind to.
Any ideas?
Your assessment of the problem is correct. A simple solution would be to use
delegate. E.g.,Edit: more info on
delegateand why it works on dynamically created elements after event binding can be found here: http://api.jquery.com/delegate/