title: How to add value to an array on click event
body: <p>What I am trying to achieve is to read value on click event and save it to an array. My code:</p>
  
  <pre><code>&lt;a href='#' class="hotel" data-hotel-name='Holiday Inn'&gt;Add to favourites&lt;/a&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>var hotelName = [];    
  $('.hotel').on('click', function(e){
      e.preventDefault();    
      hotelName.push( $(this).data('hotel-name') );
  });    
  console.log(hotelName.length);
  </code></pre>
  
  <p>The output is always <code>0</code>. Could someone tell me what am I doing wrong, please?</p>