How to get clicked indeterminate checkboxes to 'checked' state

It turns out that if the checkbox that was clicked has an indeterminate state, by the first instruction within the click event, that property has gone already.

I have replaced my logic to test something that has not faded away yet :

<script type="text/javascript">
    $(document).ready(function() {
        $(".UndefinedCheckboxState :checkbox").prop("indeterminate", true);

        $(":checkbox").click(function () {
            if ($(this).closest("span").hasClass("UndefinedCheckboxState")) {
                $(this).prop("indeterminate", false);
                $(this).prop("checked", true);
            }
        });
    });
</script>

Extending @adeneo's answer, try this:

$(document).ready(function () {
    $(".UndefinedCheckboxState input[type='checkbox']").prop("indeterminate", true);

    $("input[type='checkbox']").on('click', function () {
        console.log('changed');
        console.log('current value: '+$(this).prop('checked') );  
    });
});

View on Fiddle

Tags:

Jquery