jQuery

jQuery Checkbox Checked or not: 1 line solution

In this article, I am going to present you with 1 line solution to find if Checkbox is Checked or not using jQuery.

How to check if checkbox checked or not using jQuery – Example

For the sake of example, I am assuming that we have a checkbox with ID “mycheckbox”. We wold like to attach different functionality to this checkbox based on whether this checkbox was checked or not. We can do it in the following way:

Example: Check if checkbox is checked or not using jQuery

<html>
<head>
<title>Examples to check if a Checkbox is Checked or not using jQuery</title>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
</head>

<body>

<input name="mycheckbox" type="checkbox" id="mycheckbox" /> Check / Uncheck this checkbox and click the button below to see the alert

<p>	
<input type="submit" name="sbt_check" id="sbt_check" value="Check">
</p>

<script type="text/javascript" language="javascript" >

$(document).ready(function(){

	$('#sbt_check').on("click", function(e){				

		if( $("#mycheckbox").is(':checked') ) 
		{
			alert('Checkbox is checked!');			
		} 
		else 
		{ 
			alert('Checkbox NOT checked!');
		}

		e.preventDefault();

	});				

});	

</script>
</body>
</html>
Your turn!

Do you know of any other way to find out if a checkbox is checked using jQuery? Please feel free to share your comment below.

Share your thoughts, comment below now!

*

*