How to change with jQuery a data attribute of a set of elements? -
say have set of elements $elements. have data attr named "amount". first 1 has data-amount = 1, second 2 , on. whats simplest way increment in x value of them. y solution is
$elements.each(function(){ $(this).data('amount',$(this).data('amount')+=x); });
is there better solution, without using each statement? thanks!
jquery, of v1.6.2 @ least, doesn't offer overload .data()
accepts function. still using each
, within can do:
$(this).data().amount += x;
Comments
Post a Comment