Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery (UI): Detect checking of a checkbox

How can I make jQuery fire an event when a user checks a checkbox?

<input type="checkbox" id="test" name="test" /><label for="test">Check me</label>

I could do it with .click though that doesn't work when the user tabs to the checkbox. I wasn't able to find info on this in the API docs or while Googling.

like image 527
Maurice Avatar asked Dec 07 '22 02:12

Maurice


1 Answers

$('#test').bind('change', function(){
    if($(this).is(':checked')){
        // box was checked
    }
});
like image 180
jAndy Avatar answered Dec 20 '22 19:12

jAndy