jQuery get checkbox value if checked and remove value when unchecked

checkbox, function, javascript, jquery

Solution

You don't need an interval, everytime someone changes the checkbox the `change` event is fired, and inside the event handler you can change the HTML of `#show` based on wether or not the checkbox was checked :

$('#check').on('change', function() {
    var val = this.checked ? this.value : '';
    $('#show').html(val);
});

FIDDLE

Problem

jQuery function to get checkbox value if checked and remove value if unchecked. example here ``` <input type="checkbox" id="check" value="3" />hiiii <div id="show"></div> function displayVals(){ var check = $('#check:checked').val(); $("#show").html(check); } var qqqq = window.setInterval( function(){ displayVals() }, 10 ); ```

Original source