dimanche 15 février 2015

Push a variable into an array and update the array each time we click?


I am saving a variable into an array with a click on an item, but this should change each time I click on a different item. Currently this is alerting the same value and not the new one.



<div class="item">
<span id="0" class="video" data-vimeoid="http://vimeo.com/XXX"></span>
</div>
<div class="item">
<span id="1" class="video" data-vimeoid="http://vimeo.com/SSS"></span>
</div>
<div class="item">
<span id="2" class="video" data-vimeoid="http://vimeo.com/ZZZ"></span>
</div>


Then in jQuery



var previous = [];
$(document).on( 'click', '.item:not(.is-expanded)', function() {
var url = videoSpan.data("vimeoid");
previous.push(url);
alert(previous[0]);
});




Aucun commentaire:

Enregistrer un commentaire