i trying implement checkbox on change in jquery, checkbox checked state working when unchecked not work
$(document).ready(function() { $('.chk').click(function() { if (this.checked) { var selectitem = parseint($(this).closest('.accordion-group').find('.selectitem').text()); if (selectitem != 0) { $(this).closest('.accordion-group').find('.selectitem').text(selectitem - 1); } else { $(this).closest('.accordion-group').find('.select').hide(200); } } else { var selectitem = parseint($(this).closest('.accordion-group').find('.selectitem').text()); $(this).closest('.accordion-group').find('.selectitem').text(selectitem + 1); $(this).closest('.accordion-group').find('.select').show(200); } }); });
try : use on change event instead of click event handler. on change event give changed state i.e. checked or unchecked.
$(document).ready(function() { $('.chk').change(function() { if ($(this).is(':checked')) { var selectitem = parseint($(this).closest('.accordion-group').find('.selectitem').text()); if (selectitem != 0) { $(this).closest('.accordion-group').find('.selectitem').text(selectitem - 1); } else { $(this).closest('.accordion-group').find('.select').hide(200); } } else { var selectitem = parseint($(this).closest('.accordion-group').find('.selectitem').text()); $(this).closest('.accordion-group').find('.selectitem').text(selectitem + 1); $(this).closest('.accordion-group').find('.select').show(200); } }); });
Comments
Post a Comment