How do I to catch check/uncheck event of with jQuery?
The click will affect a label if we have one attached to the input checkbox?
I think that is better to use the .change() function
<input type="checkbox" id="something" />
$("#something").change( function(){
alert("state changed");
});
Use the :checked selector to determine the checkbox's state:
$('input[type=checkbox]').click(function() {
if($(this).is(':checked')) {
...
} else {
...
}
});
use the click event for best compatibility with MSIE
$(document).ready(function() {
$("input[type=checkbox]").click(function() {
alert("state changed");
});
});