jquery - Get the current value of a span -
right upon selection of checkboxes, adds assigned price, doesn't subtract upon de-selection. how check amount of $('.amount')
, proper math?
i made fiddle here display i'm working with.
$(':checkbox').change(function(){ var amount = $('.amount').html(); sum = number(amount.replace(/[^0-9\.]+/g,"")); var names = $(':checked').map(function(){ sum += (this.value - 0); return this.name; }).get().join(','); $('span.amount').text('$' + sum); spans[1].innerhtml = sum; });
how keeping track of original amount , starting that, this:
var originalamount = number($('.amount').html().replace(/[^0-9\.]+/g,"")); $(':checkbox').change(function(){ var sum = originalamount; // rest of code stays same.
edit: forgot point out added "var" in front of "sum", local variable.
Comments
Post a Comment