Vince V.
Vince V.

Reputation: 3143

Jquery loading dynamic libraries

I am making a script where my jquery loads a jquery plugin with the getScript() method. But for some reason the code that I load only works after my script has ended.

So the procedure:

  1. load jquery
  2. do the getScript() method and load the plugin.
  3. try to use the plugin ($('#test').myPlugin()) but crashes.
  4. script ended. try $('#test').myPlugin() in chrome web developer. Works perfectly.

Upvotes: 1

Views: 185

Answers (1)

Johan
Johan

Reputation: 3212

The getScript()-method retrieves the script asynchronous, so you have to wait till it has loaded (usually through the success()-method) to call it. I guess you're not doing that.

So try

getScript("script").success(function() {
    $('#test').myPlugin();
});

Upvotes: 1

Related Questions