title: Global Variable Jquery
body: <p>I've asked this question before but never actually got it working.</p>
  
  <p>More or less, I have multiple JS files, that I need to check against the one variable. I have a function that checks to see if a class exists and then changes the variable.</p>
  
  <pre><code>var states = function(){
  
      if($('#Animation.switch.switchOff').length == 1){
          animationtoggle = 0;
      }
      else {
          animationToggle = 1 ;
      }
      if($('#Autoscroll.switch.switchOff').length == 1){
          scrolltoggle = 1;   
      }
      else {
          scrolltoggle = 0    
      }
      return {
          animationtoggle: animationtoggle,
          scrolltoggle: scrolltoggle
      };
  }
  </code></pre>
  
  <p>I then have inside another function, in another JS file this: </p>
  
  <pre><code>Okay, I've done this, although It still doesn't fix my problem of being able to use this variable on another file, I have this inside the function: 
  
  $(function() {
      var ss = states();
      ss.animationtoggle;
      var last_position = 0;
      var duration = 300;
      if (animationtoggle == 1){
         //only do something if it's equal to 1 "on"
  });
  </code></pre>
  
  <p>And this is the toggle button code: </p>
  
  <pre><code>$('#optionMenu ul li').click(       
  function() {
  $(this).toggleClass('switchOff');
  var ss = states();
  ss.scrolltoggle;
  ss.animationtoggle; 
  });
  </code></pre>
  
  <p>Am I approaching this the right way? </p>
  
  <p>Please help! Here's my site, the toggle is up the right hand corner at the moment :<a href="http://shannonhochkins.v5.cloudsvr.com.au/" rel="nofollow">http://shannonhochkins.v5.cloudsvr.com.au/</a></p>