How to check if a checkbox has been checked using JQuery

9 sec read

The following code checks if a checkbox has been checked

var checkBox = $("input[name='myCheckBox']:checked").val(); 
 
if(checkBox == 'on'){
   alert('CHECKED!!');
}else{
   alert('NOT CHECKED');
}

myCheckBox is the name of the checkbox element

e.g.

<input type="checkbox" name="myCheckBox" />

Last Updated On March 21, 2018

Leave a Reply

avatar
  Subscribe  
Notify of