Catch checked change event of a checkbox

omg picture omg · Sep 21, 2009 · Viewed 235.4k times · Source

How do I to catch check/uncheck event of <input type="checkbox" /> with jQuery?

Answer

marcgg picture marcgg · Sep 21, 2009
<input type="checkbox" id="something" />

$("#something").click( function(){
   if( $(this).is(':checked') ) alert("checked");
});

Edit: Doing this will not catch when the checkbox changes for other reasons than a click, like using the keyboard. To avoid this problem, listen to changeinstead of click.

For checking/unchecking programmatically, take a look at Why isn't my checkbox change event triggered?