say I have a set of elements $elements. Say they all have a data attr named “amount”. First one has data-amount = 1, second 2 and so on. Whats the simplest way to increment in x that value for all of them. y solution is
$elements.each(function(){
$(this).data('amount',$(this).data('amount')+=x);
});
Is there a better solution, without using the each statement?
Thanks!
jQuery, as of v1.6.2 at least, doesn’t offer an overload for
.data()that accepts a function. Still usingeach, but within it you can do: