How to check if a checkbox has been checked using JQuery

H

How Can We Help?

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" />

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me