0

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?

1 Answer 1

2

It's not a JSON value, I don't know why you're talking about JSON values... But anyways:

nameElem.data("index",index);

That should do it.

Sign up to request clarification or add additional context in comments.

2 Comments

That did it - what is it then, if it's not a JSON value - sorry I thought it was one - today was actually my first time dealing with JSONification so I just assumed this was it. Anyways - what type of value is it, @Kolink ?
It's a data attribute. JSON is a string that represents an object, such as "{foo:'bar'}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.