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:
- load jquery
- do the getScript() method and load the plugin.
- try to use the plugin ($('#test').myPlugin()) but crashes.
- script ended. try $('#test').my开发者_C百科Plugin() in chrome web developer. Works perfectly.
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();
});
精彩评论