Skip to content
Advertisement

Check if each() index 1 et index 2 has .prop( ‘checked’ )

How to check in a each() function if the first and the second matched element have the prop checked ?

$(document).on('click', '#submitBtn', function(e) {
        var $this = $(this),
            $checkboxItems = $('input:checkbox[name="checkbox-acceptance"]');
        
            
        $checkboxItems.each(function( index ){

            // if index 0 and index 1 have .prop( 'checked ' ) do stuff ..

        }       
})

Advertisement

Answer

You don’t want to use each for this. Just check the values with simple indexing:

if ($checkboxItems[0].checked && $checkboxItems[1].checked)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement