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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -