I am trying to loop through an array of elements with a particular data tag value so that I can change the value of the data tag inside of the loop. I thought it would be fairly simple but I'm struggling. There are elements with the data tag row that have the value of "new". All I'd like to do is change the values from "new" to "old". Here is the code that I have. The jQuery selection of data-row='new' returns 3 elements. But when I check the values of these data tags, they have not changed, and there are no elements with data tags of "[data-row='old']". What am I missing?
var setNewRowToFalse = function(e) {
$.each($("[data-row='new']"), function(idx, elem) {
$(elem).data("row", "old");
});
};
Use
.attr('data-row', 'old')
instead.Check data function docs.