Checkbox .Checked plugin

by Cyberjetx

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"/><br>
    <input class="fooOne" type="checkbox"/> Assume Data is '1' <br>
    <input class="fooZero" type="checkbox"/> Assume Data is '0' <br>
    <input class="foo1" type="checkbox"/> Assume Data is 1 <br>
    <input class="foo0" type="checkbox"/> Assume Data is 0 <br>
    <input class="chkTest" type="checkbox"/> chk Test
</div>
<div>
    <button id="check">Check</button>
    <button id="uncheck">Un-Check</button>
    <button id="toggle">Toggle</button>
    <button id="oneOrzero">Imperfect Data</button>
    <button id="btnChkTest">chk Test</button><hr/>
    <span class="chkd">Results ... </span>
</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; });
        } else if(value === 1 || value === '1') {
            $(this).each(function(){ this.checked = true; });
        } else if(value === 0 || value === '0') {
            $(this).each(function(){ this.checked = false; });
        }
        return this;
    };
    
})( jQuery );

$(function() {
    
    $('#check').click(function() {
        $(':checkbox').checked(true);
    });
    
    $('#uncheck').click(function() {
        $(':checkbox').checked(false);
    });
    
    $('#toggle').click(function() {
        $(':checkbox').checked('toggle');
    });
    
    $('#oneOrzero').click(function() {
        $('.fooOne').checked('1');
        $('.foo1').checked(1);
        $('.fooZero').checked('0');
        $('.foo0').checked(0);
    });    
    
    $('#btnChkTest').click(function() {
		$('.chkd').html('8 chk Test is checked: ' + $('.chkTest').is(':checked')) ;
    });    
    
    
});