jQuery example for most used checkbox operation

Checkbox operation jQuery, jQuery checkbox is checked, jQuery checkbox checked or not, jQuery checkbox event, jQuery example for most used checkbox operation, jQuery common operations on checkbox, jQuery example for most used checkbox operation.

jQuery most used checkbox code samples that will definitely help you in your regular coding work.

Example given for most used checkbox related jQuery coding samples that we know but always google when want to use.

How to check if checkbox is checked or not checked:


//Code returns true/false based on checked status
$('#first').is(':checked');

How to get value of checked checkbox:





<input class="chk-group" type="checkbox" name="first" id="first1" value="First"/>
<label for="first1">First</label><br/>
<input class="chk-group" type="checkbox" name="second" id="second1" value="Second"/>
<label for="second1">Second</label><br/>
<input class="chk-group" type="checkbox" name="third" id="third1" value="Third"/>
<label for="third1">Third</label><br/><br/>
<button onclick="getSelectChkVal();">Get selected checkbox values</button><br/>

<script>
function getSelectChkVal(){
var str = '';
var chkList = $('.chk-group');
$.each(chkList, function(key, chkObj){
 if($(chkObj).is(':checked')){
  //CONCAT CHECKED VALUE IN STRING
  str += $(chkObj).val()+' ';
 }
});

alert('SELECTED CHECKBOX VALUE:'+"\n"+str);
}
</script>

How to check/uncheck checkbox by jQuery:


//CHECH
$('#first').prop('checked', false);

//UNCHECK
$('#first').prop('checked', false);

Have you remember some more useful info for checkbox and jQuery? Share it here by comment section.
If you like this, don’t forget to share with others.