How to check if a checkbox is checked or not using jquery/javascript

Use this simple code to check if a checkbox is checked or not using jquery/javascript

Using simple javascript

<script type="text/javascript">
   if(document.getElementById('idOfCheckbox').checked) {
		//checkbox is checked
	} else {
		//checkbox is not checked
	}
</script>

Using jquery

<script type="text/javascript">
   if($('#idOfCheckbox').prop('checked')) {
		//checkbox is checked
	} else {
		//checkbox is not checked
	}
</script>

Published: January 04 2016

blog comments powered by Disqus