title: How to set a variable depending on the event handler in the same function with jQuery?
body: <p>I'm struggling with something that might be simple for some experimented jQuery devs.</p>
  <p>I'd like to pass a variable through two event handlers and get the final value outside the events.</p>
  <pre><code>function myfunction(){
  
   var val = &quot;&quot;;
  
   $(document).on('keyup',function(e) {
     if(e.which == 13) {
       val = &quot;keyup&quot;;
       console.log(val);  
     }
   });
  
   $('#list li').click(function() {
     val = &quot;click&quot;
     console.log(val); 
   });
  
   console.log('final val =' + val);
  
  }
  
  
  $(document).ready(function(){
   myfunction();
  });
  </code></pre>
  <p>So basically, I should get two messages in the console with the same &quot;val&quot; !</p>
  <p>Any idea on how to make it work ?</p>
  <p>If any information is missing, please let me know in the comment section !</p>