Disable specific checkbox

If img element found inside the then disable the checkbox of that div.

by dhavalbharadva

HTML

<div class="classContainer">
    <label class="test">
        <img data-disable-checkbox="true">
        <input type="checkbox" class="chk" /> <span>
                This checkbox value        
            </span>

    </label>
    <label class="test">
        <input type="checkbox" class="chk" /> <span>
                This checkbox value        
            </span>

    </label>
    <label class="test">
        <img data-disable-checkbox="true">
        <input type="checkbox" class="chk" /> <span>
                This checkbox value        
            </span>

    </label>
</div>

JavaScript

$(document).ready(function () {
    $('.test').each(function () {
        if ($(this).find('img').length > 0) {
            if ($(this).find('.chk').not(":checked")) {
                $(this).find('.chk').prop("disabled", true);
                $(this).find('.chk').next('span').css('text-decoration', 'line-through');
            }
        }
    });
});