I am trying to sum the values of elements on my page. They consist of Slider elements and Checkbox elements. My sliders have a class of ".valuez" and I am targeting my checkboxes with "input[type=checkbox]". The snippets below both work great separately, but I need them to function as one to ultimately give me the sum of all values on my page.
$('.valuez').change(function(){
var sum = 0;
$('.valuez').each(function(){
sum += isNaN(this.value) || $.trim(this.value) === '' ? 0 : parseFloat(this.value);
});
$('li').html(sum);
});
$('input[type=checkbox]').change(function(){
var sum = 0;
$('input[type=checkbox]').each(function(){
sum += isNaN(this.value) || $.trim(this.value) === '' ? 0 : parseFloat(this.value);
});
$('li').html(sum);
});
<script src="http://ift.tt/1oMJErh"></script>
Aucun commentaire:
Enregistrer un commentaire