title: (jquery/javascript) How would I make click function work after key event
body: <p>I have two divs with id "display" and "display2" where i put the results of my functions.</p>
  
  <p>What the code below does is print <code>one two three four</code> in a row with a span starting around <code>one</code> and when you press the left and right keys, it removes the span on the previous item and puts a span on the next item.</p>
  
  <p>I also have a click function at the very bottom that, when span is clicked, display2 will display a number that should count up. </p>
  
  <p>The problem is:</p>
  
  <p>When screen loads, and no keys are pressed, clicking on spans, for example, <code>&lt;span&gt;one&lt;/span&gt;</code> will increase the number count in display 2 normally. </p>
  
  <p>Once I press the left and right keys, and let's say the span is on <code>&lt;span&gt;three&lt;/span&gt;</code>, if I click try clicking <code>&lt;span&gt;three&lt;/span&gt;</code>, the counter in #display2 doesn't do anything. Why is this and how can I fix it?</p>
  
  <pre><code>   var arr1 = ["one ", "two ", "three ", "four "];
      var arr2 = ["&lt;span&gt;one &lt;/span&gt;", "two ", "three ", "four "];
      var counter = 0;
  
  function count(){
    if (counter&gt;0 &amp;&amp; event.keyCode==37){
      counter--;
    }
    else if (counter&lt;3 &amp;&amp;event.keyCode==39){
       counter++;
             }
  }
  
  function spaN() {
    arr2[counter] = '&lt;span&gt;' + arr1[counter] + '&lt;/span&gt;';
      if (event.keyCode==37){
     arr2[counter+1] = arr1[counter+1];
    }
    else if (event.keyCode==39){
     arr2[counter-1] = arr1[counter-1];  
             }
  }
  
  $(document).keydown(function(event){
  switch(event.keyCode){
    case 37:
      count();
      spaN();
      $('#display').html(arr2);
      break;
    case 39:
      count();
      spaN();
      $('#display').html(arr2);    
      break;
         }
  });
  
  $('#display').html(arr2);
  
  var k = 0;
  $('span').click(function(){
  k++;
   $('#display2').html(k);
  })
  </code></pre>