title: How to define a var in jQuery that works for multiple click() functions
body: <p>I defined an array in jQuery from which I want randomly select an item and display it on the website but also give the option to tweet this exact item. Have a look at my code which I defined within the <code>&lt;script&gt; ... &lt;/script&gt;</code> element.</p>
  
  <pre><code>    $(document).ready(function() {
          $("#click").click(function() {
              var quotPick = quotes[Math.floor(Math.random()*quotes.length)];
              $("#text").text(quotPick);
          });
          $("#tweet").click(function() {
              var quotPick = quotes[Math.floor(Math.random()*quotes.length)];
              window.open('https://twitter.com/intent/tweet?hashtags= cali, hank&amp;text=' + quotPick);
          }); 
      });
  </code></pre>
  
  <p>If I write the code like that the <code>quotPick</code> variable will always be differently tweeded than displayed. If I define it outside the <code>$(#click)...</code> or even before the <code>$(document).ready ...</code> I will only be able to click at the button once to generate an item selection.</p>
  
  <p>Where or how do I have to define the <code>quotPick</code> so that my code works? Where was I making wrong assumptions? Thanks in advance, guys!</p>
  
  <p>P.S. I tried the <code>onclick()</code> function for the button as well but didn't find a satisfying solution either. </p>