A construct that hides all items that have a checkbox:checked .
$('.list input:checkbox:checked').each(function(){ $(this).parent().hide(); }) How to apply a negation to a condition to hide elements that are not checked?
A construct that hides all items that have a checkbox:checked .
$('.list input:checkbox:checked').each(function(){ $(this).parent().hide(); }) How to apply a negation to a condition to hide elements that are not checked?
For this you can use the selector :not
$('.list input:checkbox:not(:checked)').each(function(){ $(this).parent().hide(); }) Or a similar method .not
$('.list input:checkbox').not(':checked').each(function(){ $(this).parent().hide(); }) In addition, you can opt out of .each , since most jQuery methods are sharpened to work with collections. The code might look like this:
$('.list input:checkbox').not(':checked').parent().hide(); $('input[type=checkbox]:not(:checked)').hide(); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" name="name" value="value1"> <input type="checkbox" name="name" value="value2"> <input type="checkbox" name="name" value="value3" checked> <input type="checkbox" name="name" value="value4"> <input type="checkbox" name="name" value="value5" checked> Source: https://ru.stackoverflow.com/questions/839357/
All Articles