Reputation: 320
I have below script code
(function($) {
$.fn.youamaAjaxLogin = function(options) {
function start() {
//start
}
....
How can I call function start() outside
(function($) {
Please help
Upvotes: 4
Views: 415
Reputation: 19953
Assuming start()
uses variables/function also defined within its parent anonymous function, the easiest way I can think of is to create a variable outside of jQuery, which you assign. Then you can call it both inside the jQuery and outside the jQuery.
Note: the downside of this is that you can only call start();
once the page has finished loading. If you try and call start();
before that, it will cause console errors.
Here's an example...
var start = null;
$(function(){
var exampleVariable = "hello world";
start = function() {
alert(exampleVariable);
}
// You can call the function as normal here...
// start();
});
// You cannot call it here, because the page won't have loaded, so start won't be defined
// start();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" onclick="start();" value="Call Function"/>
Upvotes: 3
Reputation: 9183
Make sure that in the header of your page you include jQuery first before you add the plugin. Then after that, you can add the script tag of your own javascript files that use the plugin. So:
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!-- Plugin -->
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<!-- MyFile -->
<script src="/js/MyFile.js"></script>
Then your file will be able to use all the plugin functions.
Upvotes: -2