I have 4 checkboxes: one "All" and three different element. The different elements has a class, the "All" checkbox has an id. I want to make checked the "All" checkbox if not checked any other elements. I made this code but not working (Mind means All)
$(document).ready(function() {
$('#check-nemek-mind').click(function() {
$('.check-nemek').prop('checked', false);
$('#check-nemek-mind').prop('checked', true);
});
$('.check-nemek').click(function() {
$('#check-nemek-mind').prop('checked', false);
if (document.getElementByClass('check-nemek').checked) {} else {
$('#check-nemek-mind').prop('checked', true);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="checkbox">
<label><input type="checkbox" id="check-nemek-mind" rel="nemek-mind" checked /><strong>Mind</strong></label>
</div>
<div class="checkbox">
<label><input type="checkbox" class="check-nemek" rel="nemek-noi"/>Női divat</label>
</div>
<div class="checkbox">
<label><input type="checkbox" class="check-nemek" rel="nemek-ferfi"/>Férfi divat</label>
</div>
<div class="checkbox">
<label><input type="checkbox" class="check-nemek" rel="nemek-gyerek"/>Gyerek divat</label>
</div>
Aucun commentaire:
Enregistrer un commentaire