I have this little script. I need to add and remove elements at my shop basket. So i have a simple counter, but it’s not work corectly. When i’m parsing actual number and add another one everythin is fine, but – i can’t add another one, and when i’m subctracting it brings me an zero. Can you help me? My code and some fiddle http://jsfiddle.net/5vuJQ/:
$(function(products_counter){
var n = parseInt($('.lce_number').text());
var n_place = $('.lce_number');
$('.lce_add').live('click', function(){
n_place.empty().append(n + 1);
});
$('.lce_remove').live('click', function(){
n_place.empty().append(n - 1);
});
});
You have to pick up the number from
.lce_numberon each click. Note,live()method was deprecated, you should useon()instead.DEMO: http://jsfiddle.net/5vuJQ/7/