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. 

updated jsfiddle

edit: forgot point out added "var" in front of "sum", local variable.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -