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