3

In a project where we use Bootstrap, we have a page where lots of partial tempaltes can be loaded in the centre, using ajax.

In a partial template, I have a modal, but it doesn't work, because the behaviour needs to be bound somehow. I could manually bind it as part of the template, but I feel this is too messy. I'd like to be able to "refresh the API to allow the behaviour i need.

I've seen that the following function $(document).off('.data-api') will unbind all the functions associated with that API.

Is there an equivalent where I can manually turn it back on? Or otherwise update the binding in a general way that takes care of any new content?

Perhaps I'm going about this the wrong way and another solution or approach is better?

daveyfaherty
  • 4,585
  • 2
  • 27
  • 42
  • Would stripping/altering the data-api work maybe? e.g. Convert `data-api="x"` to `data-inactive-api="x"` by a quick `.attr()` change, thus `bootstrap.js` will stop listening to those nodes, then revert back when needed. – MackieeE Dec 11 '13 at 10:27
  • Will [.on()](http://api.jquery.com/on/) unbind it? I thought [.off()](http://api.jquery.com/off/) did that. – Henrik Andersson Dec 11 '13 at 10:29
  • Thanks limielights, I've fixed that now. Yes, I meant "off". – daveyfaherty Dec 11 '13 at 10:36

1 Answers1

0

$(document).off( events [, selector ] [, handler(eventObject)]) is the right syntax for this.

So, you pass the even as the first param in the function and then selector. or you can unbind all the events from particular selector like: $(document).off();

use any of them and then try biding with $(document).on(event, [selector], [handler]);

Good luck!

Ashish Kumar
  • 2,991
  • 3
  • 18
  • 27