Jquery checkbox toggle

For checkbox input type, when we tick checkbox we have enabled an input element enclosed in a div tag and when this checkbox in unchecked we hide the same.


<!DOCTYPE html>
<title>jQuery Toggle 2</title>
	$(document).ready(function() {
		$("#privatePostPassword").hide(); // hiding div on load

		$("#postPublicOrPrivate").change(function() { // change event for checkbox
			// checking if the box is checkedm if yes execute this otherwise else
			if (this.checked) { 
			} else {
	Do you have any criminal convictions :

	<input id="postPublicOrPrivate" type="checkbox" />

	<div id="privatePostPassword">
		<input type="text" class="form-control" id="postPassword" />



Checkbox checked Checkbox unchecked
checked unchecked

You may also like...