JSFiddle - React, Tailwind, and code Playground
HTML
<input type="checkbox" id="selecctall"/> Selecionar tudo
<br /><input class="checkbox1" type="checkbox" name="check[]" value="item1"> Item 1
<br /><input class="checkbox1" type="checkbox" name="check[]" value="item2"> Item 2
<br /><input class="checkbox1" type="checkbox" name="check[]" value="item3"> Item 3
<br /><input class="checkbox1" type="checkbox" name="check[]" value="item4"> Item 4
<br /><input class="checkbox1" type="checkbox" name="check[]" value="item5"> Item 5
<br /><input class="checkbox1" type="checkbox" name="check[]" value="item6"> Item 6
<br /><input class="checkbox2" type="checkbox" name="check[]" value="item6"> Esta não seleciona
JavaScript
$(document).ready(function() {
$('#selecctall').click(function(event) { //on click
if(this.checked) { // check select status
$('.checkbox1').each(function() { //loop through each checkbox
this.checked = true; //select all checkboxes with class "checkbox1"
});
}else{
$('.checkbox1').each(function() { //loop through each checkbox
this.checked = false; //deselect all checkboxes with class "checkbox1"
});
}
});
});