views:

53

answers:

1

When load the new html from a post function I lose all of my click bindings. I read that i could use live to keep all the bindings but can't find any examples where live is used with post. Here is my code:

$('.GroupHeader').unbind('click').live('click', function (event) {
        event.preventDefault();
        TemplateEditor.SelectGroupClicked($(this));
    });
+2  A: 

You should use live to bind your click event handlers, i.e.:

$(selector).live('click', function () {
  //...
});

Instead of :

$(selector).click(function () { // or $(selector).bind('click', ...
  //...
});

In that way, doesn't matter your elements are replaced, the events will still work, because live works with event delegation.

CMS
OK..I have reposted the code can you take a look.
Luke101
@Luke101: `live` doesn't work like that, `live` lets you bind events, and `'post'` is not an event. The `AddGroup` function should stay like before your edit, you should change the code where you add the click event handlers....
CMS
Sorry for all the questions. I have changed again for the click event. But this way still does not work.
Luke101
Actually, Ill take that back..This does work. Thanks for your help
Luke101
OK..I have got a really good working version. Would you have any suggestions?
Luke101