JSFiddle - React, Tailwind, and code Playground
by xixonia
HTML
<div>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
</div>
<div>
<button id="check">Check</button>
<button id="uncheck">Un-Check</button>
<button id="toggle">Toggle</button>
</div>
CSS
div
{
padding:10px;
margin:5px;
border: 1px solid black;
}
JavaScript
(function( $ ) {
$.fn.checked = function(value) {
if(value === true || value === false) {
// Set the value of the checkbox
$(this).each(function(){ this.checked = value; });
} else if(value === undefined || value === 'toggle') {
// Toggle the checkbox
$(this).each(function(){ this.checked = !this.checked; });
}
};
})( jQuery );
$(function() {
$('#check').click(function() {
$(':checkbox').checked(true);
});
$('#uncheck').click(function() {
$(':checkbox').checked(false);
});
$('#toggle').click(function() {
$(':checkbox').checked('toggle');
});
});