How do you get the value set in this plugin out again?
Example below shows a variable I want available on the page anywhere I need to call it. put all I get is undefined?
plugin.js
(function($) {
$.fn.myPlugin = function(options) {
options.val ++;
// access and modify 'somevar' here so that it gets modified
// in the function which called a plugin
};
})(jQuery);
script on page
<script>
$(document).ready(function(){
var somevar = {val: 5};
$(document).myPlugin(somevar);
});
</script>
<script>
$(document).ready(function(){
alert(somevar.val);
});
</script>
Your somevar is declared local in the first $(document).ready(), to be accessible in the second one you should rather do :