Catching When A Checkbox Is Clicked

jQuery makes it really easy to catch when a HTML checkbox is clicked.

        ... Do Something ...

or you could:


A change to the checkbox will fire the change event.

A Complete Example (CheckBoxDemo.html):

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<input type="checkbox" name="theNameForCheckbox" id="theCheckBox_ID">
<label for="theCheckBox_ID"> Click on the Checkbox or on this label. </label>

<div id="output"></div>

<script src="js/jquery-1.10.2.js"></script>


		if ( $("#theCheckBox_ID").is ( ':checked' ) ) {
			$("#output").html("It is Checked");
		} else {
			$("#output").html("It <b>not</b> Checked");



•       •       •       •       •       •

Summary: # of Words: 70
Author: Philip Schlump
Published On: 2013-05-05

Download code from this articles in .tar.gz for Mac/Linux/Unix or .zip with CR/LF for Windows format.


Before You Go....

Have you read "Unintend Consinsequences"?

"I laughed so hard it hurt..."
    Rod Brown

"Incredibly funny! Incredibly true!"
    Tad Stevens