1

I know that jQuery has .on() and .delegate() methods, but these require the event to bubble. I want to load slickGrid and some other 'on load' plugins.

Is there anyway to call these without having to define them in the callback after an ajax request has loaded the new dom?

Thanks!

1 Answer 1

2

Stick all your initialisation code inside $(function() { ... });

For example,

$(function() {
  var slickgrid = new Slick.Grid("#slickgrid", 10, 3, {});
  // any other initialisation code...
});
Sign up to request clarification or add additional context in comments.

3 Comments

But I have grids and other items that are being loaded via ajax, so after the ajax success, I call these plugins (which I'd rather not do). They aren't recognized outside of this.
What isn't recognised outside of what? If you mean the slickgrid variable in my example above, you can move the declaration outside the function, make it a bit more global, so it is accessible from your ajax success handler. Regarding the initialisation from the ajax success handler, why is it something you'd rather not do? If it's dependent on that data, it's the sensible way to do it, no?
Yeah, I guess it's fine. I have a ton of other dependent plugins, so it tends to get messy to have it all in a callback, but I'll put it in a plugin then call that plugin from within the callback. Wasn't sure if there was a better method through jQuery for non-bubbled "events". Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.