JSFiddle - React, Tailwind, and code Playground

by vikastyagi87

HTML

<div id="pakker">
    <input type="checkbox" value="39" />test 1<br/>
    <input type="checkbox" value="79" />test 2<br/>
    <input type="checkbox" value="29" />test 3<br/>
    <input type="checkbox" value="49" />test 4<br/>
</div>
<div id='sum'></div>

JavaScript

jQuery(document).ready(function($) {
    var sum = 0;
    $('#pakker :checkbox').click(function() {
        sum = 0;
        
        alert(sum);
        $('#pakker :checkbox:checked').each(function(idx, elm) {
            sum += parseInt(elm.value, 10);
        });
        
        $('#sum').html(sum);
    
    });
    
});