javascript - Inaccessible global variable -


this driving me crazy.

jquery notifies me message [prevobject: r.fn.init(1)] when try retrieve variable $venusthumbdiv inside collector() function. in other words, guess jquery doesn't find $('.venus-thumb-div') inside page (althought there 4 divs class).

what's incredible in snippet below code works should identical piece of code doesn't work if write in editor , run on same browser!! way let work "offline" decommenting var declaration inside collector() function, it's totally useless 'cause need var $venusthumbdiv global.

has clue on why i'm having problem?

var venusgallery = function () {        var $venusthumbdiv              = $('.venus-thumb-div');        /* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */      /* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@       public fns       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */      /* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */      /* ~~~~~~~~~~~~~~~~~~~     collector()    ~~~~~~~~~~~~~~~~~~~ */      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */      var collector = function () {          // var $venusthumbdiv              = $('.venus-thumb-div');          console.log("div number: " + $venusthumbdiv.length);          console.log($venusthumbdiv);       };        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */      /* ~~~~~~~~~~~~~~~~~~~     setopts()    ~~~~~~~~~~~~~~~~~~~ */      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */      var setopts = function (choosen_options) {          var options = {              progression:    '<div id="venus-progression" style="color: white"></div>',              share:          '<div id="venus-share"></div>',              fullscreen:     '<div id="venus-fullscreen"></div>',              download:       '<div id="venus-download"></div>',              description:    '<p id="venus-description"></p>'          };            /* default: no options; options showed if declared , set true in venusgallery.setopts({}); */          $.each(options, function (key, value) {              if (choosen_options[key]) {                  options[key] = value;              } else {                                    // if false or not declared: not showed                  options[key] = '';              }          });            venusopts = options;      };      /* *****************************************************************************************************************       * ************************************************************************************************************** */      /* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */      /* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@       public fns definition       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */      /* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */      return {          setopts: setopts,          collector: collector      };      /* *****************************************************************************************************************       * ************************************************************************************************************** */    }();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="venus-gallery">        <div class="venus-thumb-div" data-image="../img/bv.jpg">          <img src="../img/thumb/bv_thumb.jpg" class="venus-thumb">      </div>      <div class="venus-thumb-div" data-image="../img/islamuj.jpg">          <img src="../img/thumb/islamuj_thumb.jpg" class="venus-thumb">      </div>      <div class="venus-thumb-div" data-image="../img/vertical.jpg">          <img src="../img/thumb/vertical_thumb.jpg" class="venus-thumb">      </div>      <div class="venus-thumb-div" data-image="../img/pano.jpg">          <img src="../img/thumb/pano_thumb.jpg" class="venus-thumb">      </div>        </div>      <script>      $(document).ready(function () {          venusgallery.setopts({              progression: true,              download: true,              share: true,              fullscreen: true          });          venusgallery.collector();      });  </script>


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -