JSFiddle - React, Tailwind, and code Playground
by secretgspot
HTML
<input type="checkbox" value="controller" onclick="checkall('allThese', $this);"/>
<fieldset id="allThese">
<input type="checkbox" value="1"/>
<input type="checkbox" value="2"/>
<input type="checkbox" value="3"/>
</fieldset>
JavaScript
// context = id of elements which contains checkboxes
// controller = DOMelement of ckeckbox controller
function checkall(context, controller){
$("#"+context).find("input[@type$='checkbox']").not(controller).each(function(){
// verify the state of checkbox controller and pass the state to others checkboxes
this.checked = $(controller).checked;
});
}