jquery - How to make this work when there are many itemdiv? -



jquery - How to make this work when there are many itemdiv? -

i need help in solving

this fiddle , http://jsfiddle.net/e56ty/47/

i showing topping count water ice cream (initially zero).

once in fiddle , click on strawberry or choclate , see topping count increases or decreaes each time click them .

for 1 itemdiv working fine , how can deal when there many itemdiv ??

sorry title , couldn't able think of improve 1

this listener when clicked on toppings items

var id = 71; var = 0; $(document).on("click", ".secclass a", function(e) { if($(this).hasclass("tpactive")) { = parseint(i)-1; $(this).removeclass("tpactive"); $("#"+id+".topp span").text(i); } else { = parseint(i)+1; $(this).addclass("tpactive"); $("#"+id+".topp span").text(i); } });

i think want: http://jsfiddle.net/msgz8/1/

you have aware there can no more 1 element same id. , javascript have modified:

$(document).on("click", ".secclass a", function(e) { if($(this).hasclass("tpactive")) { var element = $("#"+$(this).attr('data-id')+".topp"); var count = parseint(element.attr("data-count"))-1; element.attr("data-count", count); $(this).removeclass("tpactive"); element.find("span").text(count); } else { var element = $("#"+$(this).attr('data-id')+".topp"); var count = parseint(element.attr("data-count"))+1; element.attr("data-count", count); $(this).addclass("tpactive"); element.find("span").text(count); } });

hope helps! :)

jquery

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -