I have the following code. However, the problem with it is that it does not change nameElem.data('index'), so whenever the code runs it only shows element 1 in the list. How can I change the nameElem.data('index') json value? I tried cardInfo[i].data.index = index;, but that did not work.
$('#next').on('click', function(e) {
e.preventDefault();
var nameElem = $('#team-name');
var entries = nameElem.data('entries');
var index = (nameElem.data('index') + 1) % entries.length;
nameElem.text(entries[index]);
})
Keeping it simple: How do I set a json value - nameElem.data('index') to var index?