javascript - How do I use global variables to access plugin methods in jQuery? -
my experience jquery limited, hence please feel free edit question in case verbiage incorrect.
while initiating plugin i'm assigning variable:
var test = $('.fancybox').fancybox({ padding : 0, margin : 10, closebtn : false });
now, i'm trying access instance of plugin , call it's method as:
$(document).on('keyup', function(e) { var code = (e.keycode ? e.keycode : e.which); if (code == 40) { test.cancel(); return false; } });
this throws error — "test undefined". per understanding appears problem scope of variable test
. however, test
has been declared inside of jquery(document).ready(function($)
, such should globally available functions inside of jquery(document).ready(function($)
. doing wrong here?