I need to add and delete the number "7" based on a user checking a checkbox and then display that number on the page:
var theTotal = 0;
$("#highlightChk").change(function() {
var ishchecked= $(this).is(':checked');
if(!ishchecked) theTotal -= 7;
if(ishchecked) theTotal += 7;
});
$('#total').text(theTotal);
When I display the code it is "0" even when I check the checkbox. What am I doing wrong?
$('#total').text(theTotal);You need to put this in that change callback. Otherwise you just give#totalthe init value, but dosen't give it a new value to display whentheTotalis changed.